当前位置:网站首页>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
边栏推荐
- leetcode-6129:全 0 子数组的数目
- Leetcode-6131: the shortest dice sequence impossible to get
- wokerman 自定义写入日志文件
- Working principle of radar water level gauge and precautions for installation and maintenance
- [today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger
- 【ONNX】pytorch模型导出成ONNX格式:支持多参数与动态输入
- SecureCRT garbled code solution [easy to understand]
- Leetcode-155: minimum stack
- leetcode-155:最小栈
- Embedded development: embedded foundation -- threads and tasks
猜你喜欢
随机推荐
网络协议:TCP Part2
Jmeter——接口测试
[MCU] 51 MCU burning those things
Rand1 generates rand9
leetcode-146:LRU 缓存
leetcode-6130:设计数字容器系统
【高等数学】【5】定积分及应用
Success factors of software R & D effectiveness measurement
Key network protocols in tcp/ip four layer model
How to choose a microservice registration center?
leetcode-6127:优质数对的数目
Solution to oom exceptions caused by improper use of multithreading in production environment (supreme Collection Edition)
Question and answer 47: geeks have an appointment - the current monitoring system construction of CSC
How much memory does bitmap occupy in the development of IM instant messaging?
Recommended books | essentials of industrial digital transformation: methods and Practice
数据库清空表数据并让主键从1开始
Google guava is just a brother. What is the real king of caching? (glory Collection Edition)
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
[matlab] download originality documents based on oil monkey script and MATLAB
[today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now







![MySQL date [plus sign / +] condition filtering problem](/img/86/aed048e27b3e0b0baa919204bc067c.png)

