正如一些人可能已经注意到的,PayPal的SDK文档至少可以说是相当糟糕的,给开发人员带来了问题。
我目前的想法是关于账单计划payment_definitions。
我已经开发了一个折扣功能,它将回报给用户一个指定的金额折扣。我希望这个折扣只适用于第一个月。当涉及到创建支付定义对象时,关于计费计划的糟糕文档让我感到困惑。是否可以同时定义试用和常规付款定义?
请看下面的代码,了解我目前正在使用的示例。
if(Wo_DiscountAvailable($discount)){
// (total-(total/100*percentage))
$dc_total = ($total-(Wo_DiscountPercentage($discount)/100*$total));
$tDefinition = new \PayPal\Api\PaymentDefinition();
$tDefinition->setName('Regular Payments user' . $wo['user']['id'])->setType('TRIAL')
->setFrequency($p_type)->setFrequencyInterval('1')
->setCycles('1')
->setAmount(new \PayPal\Api\Currency(array(
'value' => $dc_total,
'currency' => $wo['config']['paypal_currency']
)));
$paymentDefinition = new \PayPal\Api\PaymentDefinition();
$paymentDefinition->setName('Regular Payments user' . $wo['user']['id'])->setType('REGULAR')
->setFrequency($p_type)->setFrequencyInterval('1')
->setCycles('47')
->setAmount(new \PayPal\Api\Currency(array(
'value' => $total,
'currency' => $wo['config']['paypal_currency']
)));
} else {
// Set billing plan definitions
$paymentDefinition = new \PayPal\Api\PaymentDefinition();
$paymentDefinition->setName('Regular Payments user' . $wo['user']['id'])->setType('REGULAR')
->setFrequency($p_type)->setFrequencyInterval('1')
->setCycles('48')
->setAmount(new \PayPal\Api\Currency(array(
'value' => $total,
'currency' => $wo['config']['paypal_currency']
)));
}
if(Wo_DiscountAvailable($discount)){
$plan->setPaymentDefinitions(array(
$tDefinition, $paymentDefinition
));
} else {
$plan->setPaymentDefinitions(array(
$paymentDefinition
));
}上面包括函数Wo_DiscountAvailable和Wo_DiscountPercentage -这两个函数都可以工作
如果前一个函数可用,则返回true或false,discount返回discount的值。
在此之前,非常感谢您。
发布于 2020-10-31 20:26:36
如果您使用的是PayPal-PHP-SDK,请停止使用。它是deprecated,它的计费方案的使用与Subscriptions API不兼容,如果您想要集成它的话。
没有用于当前订阅API的SDK;如果您正在进行基于服务器的集成,请使用直接HTTPS调用,例如PHP的curl。
如果你想要一个智能订阅按钮来调用你的服务器来获取createSubscription和激活,这样你就可以在你的数据库中保存它的记录,这里有一个指南:PayPal Smart Subscribe server side
https://stackoverflow.com/questions/64620073
复制相似问题