当前位置:网站首页>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
边栏推荐
- Recommended books | essentials of industrial digital transformation: methods and Practice
- Docker builds redis cluster
- [today in history] July 13: the father of database passed away; Apple buys cups code; IBM chip Alliance
- [today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal
- [advanced mathematics] [8] differential equation
- 火山引擎项亮:机器学习与智能推荐平台多云部署解决方案正式发布
- Remote monitoring solution of intelligent electronic boundary stake Nature Reserve
- leetcode-79:单词搜索
- Online XML to JSON tool
- 【NOI模拟赛】字符串匹配(后缀自动机SAM,莫队,分块)
猜你喜欢

Jmeter——接口测试
![Vulnhub | dc: 6 | [actual combat]](/img/7e/de7d5b56724bde5db2bb8338c35aa8.png)
Vulnhub | dc: 6 | [actual combat]
![[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

If the order is not paid for 30 minutes, it will be automatically cancelled. How to achieve this? (Collection Edition)
![[today in history] June 28: musk was born; Microsoft launched office 365; The inventor of Chua's circuit was born](/img/bf/09ccf36caec099098a22f0e8b670bd.png)
[today in history] June 28: musk was born; Microsoft launched office 365; The inventor of Chua's circuit was born

Compilation and operation of program

Docker 搭建 Redis Cluster集群

FanoutExchange交换机代码教程

Introduction to several scenarios involving programming operation of Excel in SAP implementation project

程序的编译和运行
随机推荐
Force deduction ----- calculate the money of the force deduction bank
Network protocol: TCP part2
C language file reading and writing
【高等数学】【5】定积分及应用
从底层结构开始学习FPGA(16)----PLL/MMCM IP的定制与测试
LeetCode通关:哈希表六连,这个还真有点简单
RF, gbdt, xgboost feature selection methods "recommended collection"
[advanced mathematics] [3] Application of differential mean value theorem and derivative
结构体,枚举类型与联合体
leetcode-6127:优质数对的数目
Fanoutexchange switch code tutorial
Has baozi ever played in the multi merchant system?
Leetcode-6125: equal row and column pairs
增加 swap 空间
[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
[cloud native] use of Nacos taskmanager task management
If the order is not paid for 30 minutes, it will be automatically cancelled. How to achieve this? (Collection Edition)
Formatdatetime explanation [easy to understand]
Leetcode-6126: designing a food scoring system
[tensorrt] trtexec tool to engine