当前位置:网站首页>PayPal PHP product trial period "recommended collection"
PayPal PHP product trial period "recommended collection"
2022-07-25 20:40:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
One . Provide probation period
Use probation , Enable subscribers to try your product at a free or discounted price before the start of the regular billing cycle . After the probation period , The regular billing period of the subscription begins . Each plan can have a maximum of two probation periods .
The following sample request shows how to provide a trial period . Create a plan when , Use these examples to adjust the code .
Example : Music service
This example sets a trial period with the following characteristics :
- First month $ 0.
- Every month after the probation period 15 dollar .
curl -v –X POST https://api-m.sandbox.paypal.com/v1/billing/plans \
-H "Accept: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-H "Content-Type: application/json" \
-H "PayPal-Request-Id: PLAN-18062020-002" \
-d '{
"name": "Premium Music Plus",
"description": "A premium plan with music download feature",
"product_id": "PROD-5RN21878H3527870P",
"billing_cycles": [
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "TRIAL",
"sequence": 1,
"total_cycles": 1,
"pricing_scheme": {
"fixed_price": {
"value": "0",
"currency_code": "USD"
}
}
},
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 2,
"total_cycles": 0,
"pricing_scheme": {
"fixed_price": {
"value": "15",
"currency_code": "USD"
}
}
}
],
"payment_preferences": {
"auto_bill_outstanding": true,
"payment_failure_threshold": 1
}
}'Example : Online tutorial service
This example sets a trial period with the following characteristics :
- First week $ 0 Free trial .
- Next 3 Zhou , Once a week 5 The preferential probation period of USD .
- Every week after the probation period 10 dollar .
curl -v –X POST https://api-m.sandbox.paypal.com/v1/billing/plans \
-H "Accept: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-H "Content-Type: application/json" \
-H "PayPal-Request-Id: PLAN-18062020-003" \
-d '{
"name": "Music Tutorial Premium Plus",
"description": "Offering a premium music tutorial with download feature",
"product_id": "PROD-5RN21878H3527870P",
"billing_cycles": [
{
"frequency": {
"interval_unit": "WEEK",
"interval_count": 1
},
"tenure_type": "TRIAL",
"sequence": 1,
"total_cycles": 1,
"pricing_scheme": {
"fixed_price": {
"value": "0",
"currency_code": "USD"
}
}
},
{
"frequency": {
"interval_unit": "WEEK",
"interval_count": 1
},
"tenure_type": "TRIAL",
"sequence": 2,
"total_cycles": 3,
"pricing_scheme": {
"fixed_price": {
"value": "5",
"currency_code": "USD"
}
}
},
{
"frequency": {
"interval_unit": "WEEK",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 3,
"total_cycles": 0,
"pricing_scheme": {
"fixed_price": {
"value": "10",
"currency_code": "USD"
}
}
}
],
"payment_preferences": {
"auto_bill_outstanding": true,
"payment_failure_threshold": 1
}
}`Reference documents : https://developer.paypal.com/docs/business/subscriptions/add-capabilities/trial-period/
Two . Subscription and trial buttons
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="[email protected]">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input type="hidden" name="item_name" value="Alice's Weekly Digest">
<input type="hidden" name="item_number" value="DIG Weekly">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="5.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<!-- Set recurring payments until canceled. -->
<input type="hidden" name="src" value="1">
<!-- Display the payment button. -->
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribe_LG.gif"
alt="Subscribe">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="[email protected]">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input type="hidden" name="item_name" value="Alice's Weekly Digest">
<input type="hidden" name="item_number" value="DIG Weekly">
<!-- Set the terms of the 1st trial period. -->
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a1" value="0">
<input type="hidden" name="p1" value="7">
<input type="hidden" name="t1" value="D">
<!-- Set the terms of the 2nd trial period. -->
<input type="hidden" name="a2" value="5.00">
<input type="hidden" name="p2" value="3">
<input type="hidden" name="t2" value="W">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="a3" value="49.99">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<!-- Set recurring payments until canceled. -->
<input type="hidden" name="src" value="1">
<!-- Display the payment button. -->
<input type="image" name="submit"
src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribe_LG.gif"
alt="Subscribe">
<img alt="" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
</body>
</html>Page icon
Click the effect picture :
Code example 1;
/**
* Create billing plan at paypal
*
* @param $name
* @param $description
* @param $amount
* @param string $returnUrl
* @param string $returnCancel
* @param int $setupFee
* @param bool $isTrial
* @param string $currency
* @param string $planType
* @param string $definitionName
* @param string $definitionType
* @param string $definitionFrequency
* @param string $definitionFrequencyInterval
* @param string $definitionCycles
* @param string $trialDefinitionName
* @param string $trialDefinitionType
* @param string $trialDefinitionFrequency
* @param string $trialDefinitionFrequencyInterval
* @param string $trialDefinitionCycles
* @param string $trialDefinitionAmount
* @return string
*/
function create($name, $description, $amount, $returnUrl = '', $returnCancel = '', $setupFee = 0, $isTrial = false, $currency = 'USD', $planType = 'fixed',
$definitionName = 'Regular Payments', $definitionType = 'REGULAR', $definitionFrequency = 'Month', $definitionFrequencyInterval = '1', $definitionCycles = '12',
$trialDefinitionName = 'Trial Period', $trialDefinitionType = 'TRIAL', $trialDefinitionFrequency = '0', $trialDefinitionFrequencyInterval = '0', $trialDefinitionCycles = '0',
$trialDefinitionAmount = '0')
{
$plan = new Plan();
$plan->setName($name)->setDescription($description)->setType($planType);
$paymentDefinition = new PaymentDefinition();
$paymentDefinition->setName($definitionName)
->setType($definitionType)
->setFrequency($definitionFrequency)
->setFrequencyInterval($definitionFrequencyInterval)
->setCycles($definitionCycles)
->setAmount(new Currency(array('value' => $amount, 'currency' => $currency)));
$plan->setPaymentDefinitions(array($paymentDefinition));
if ($isTrial) {
$paymentDefinitionTrial = new PaymentDefinition();
$paymentDefinitionTrial->setName($trialDefinitionName)
->setType($trialDefinitionType)
->setFrequency($trialDefinitionFrequency)
->setFrequencyInterval($trialDefinitionFrequencyInterval)
->setCycles($trialDefinitionCycles)
->setAmount(new Currency(array('value' => $trialDefinitionAmount, 'currency' => $currency)));
$plan->addPaymentDefinition($paymentDefinitionTrial);
}
$merchantPreferences = new MerchantPreferences();
$merchantPreferences->setReturnUrl($returnUrl)
->setCancelUrl($returnCancel)
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => $setupFee, 'currency' => $currency)));
$plan->setPaymentDefinitions(array($paymentDefinition));
$plan->setMerchantPreferences($merchantPreferences);
$result = $plan->create($this->getAdapter()->getApiContext());
if ($result) {
return ['plan' => $result, 'id' => $result->getId(), 'state' => $result->getState(), 'created' => $result->getCreateTime()];
}
return $result;
}During the service life ; Be sure to set the first deduction as 0: Otherwise, the normal subscription fee will be deducted every time
$this->paypal->set_merchant_preferences($returnurl, $cancelurl, 'YES', 'CONTINUE', '0', 0); // $price Set the first subscription deduction amount ***, Default 0 Means no deduction public function set_merchant_preferences($return_url, $cancel_url, $auto_bill_amount = "NO", $initial_fail_amount_action = "CANCEL",
$max_fail_attempts = 0, $agreement_fees = 0)
{
$this->merchantPreferences = new MerchantPreferences();
$this->merchantPreferences->setReturnUrl($return_url)
->setCancelUrl($cancel_url)
->setAutoBillAmount($auto_bill_amount)
->setInitialFailAmountAction($initial_fail_amount_action)
->setMaxFailAttempts($max_fail_attempts)
->setSetupFee(new Currency(array('value' => $agreement_fees, 'currency' => config_item("currency"))));
$this->plan->setMerchantPreferences($this->merchantPreferences);
return;
}Reference resources :https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/html-example-subscribe/#trial-periods
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/111560.html Link to the original text :https://javaforall.cn
边栏推荐
- 【高等数学】【1】函数、极限、连续
- Force deduction ----- calculate the money of the force deduction bank
- [leetcode] 28. Implement strstr ()
- [today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger
- 2022.7.24-----leetcode.1184
- How to obtain the subordinate / annotation information of KEGG channel
- SecureCRT garbled code solution [easy to understand]
- Follow up of Arlo's thinking
- leetcode-79:单词搜索
- Today's sleep quality record 75 points
猜你喜欢

Kubernetes advanced part learning notes

leetcode-6125:相等行列对

Learn FPGA from the bottom structure (16) -- customization and testing of pll/mmcm IP
![[cloud native] use of Nacos taskmanager task management](/img/af/f1c5359e7dbcf51f02fa32839539b2.png)
[cloud native] use of Nacos taskmanager task management

test

leetcode-6129:全 0 子数组的数目
![[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal](/img/7d/7a01c8c6923077d6c201bf1ae02c8c.png)
[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

Struct, enum type and union
![[today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace](/img/86/abeb82927803712a98d2018421c3a7.png)
[today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace

Go language go language built-in container
随机推荐
结构体,枚举类型与联合体
Introduction and construction of consul Registration Center
[paper reading] unpaired image to image translation using cycle consistent advantageous networks
Leetcode-155: minimum stack
The database empties the table data and makes the primary key start from 1
leetcode-155:最小栈
Remote monitoring solution of intelligent electronic boundary stake Nature Reserve
增加 swap 空间
TGA file format (waveform sound file format)
【TensorRT】动态batch进行推理
【NOI模拟赛】字符串匹配(后缀自动机SAM,莫队,分块)
Working principle of radar water level gauge and precautions for installation and maintenance
test
Key network protocols in tcp/ip four layer model
Why did I choose to become a network engineer after graduating from weak current for 3 months
How to use buffer queue to realize high concurrent order business (glory Collection Edition)
Leetcode-146: LRU cache
Follow up of Arlo's thinking
ROS_ Rqt toolbox
[advanced mathematics] [3] Application of differential mean value theorem and derivative