繁体   English   中英

如何使用 paypal rest-api-sdk 为具有不同计费周期和金额的 PayPal 定期付款添加多个包

[英]How add multiple packages for PayPal recurring payment with different billing cycle & amount using paypal rest-api-sdk

我已经尝试过这段代码,但它失败了。

$paymentDefinition_0 = new PaymentDefinition();
$paymentDefinition_1 = new PaymentDefinition();

$paymentDefinition_0->setName('1stPayment')
    ->setType('REGULAR')
    ->setFrequency('DAY')
    ->setFrequencyInterval('1')
    ->setCycles('1000')
    ->setAmount(new Currency(array(
        'value' => $request->20,
        'currency' => 'USD'
    )));
$paymentDefinition_1->setName('2nd Payment')
    ->setType('REGULAR')
    ->setFrequency('DAY')
    ->setFrequencyInterval('1')
    ->setCycles('1000')
    ->setAmount(new Currency(array(
        'value' => $request->30,
        'currency' => 'USD'
    )));
$plan->setPaymentDefinitions(array(
    $paymentDefinition,
    $paymentDefinition_1
));

20 和 30 在技术上是常量,您不能将它们作为表单请求中的名称或将它们作为对象的属性访问,这是语法错误

如果它们是恒定的,则硬编码这些值

$paymentDefinition_0->setName('1stPayment')
    ->setType('REGULAR')
    ->setFrequency('DAY')
    ->setFrequencyInterval('1')
    ->setCycles('1000')
    ->setAmount(new Currency(array(
        'value' => 20,
        'currency' => 'USD'
    )));
$paymentDefinition_1->setName('2nd Payment')
    ->setType('REGULAR')
    ->setFrequency('DAY')
    ->setFrequencyInterval('1')
    ->setCycles('1000')
    ->setAmount(new Currency(array(
        'value' => 30,
        'currency' => 'USD'
    )));

或者以 HTML 形式给他们一个字符串名称,然后将该名称作为请求 object 的属性访问

例如

<form action="/" method="post">
    @csrf
    <input type="number" name="paymentDefinition_0" value="20"><br>
    <input type="number" name="paymentDefinition_1" value="30"><br>
    <button type="submit">Submit</button>
</form>

并相应地访问

$paymentDefinition_0->setName('1stPayment')
    ->setType('REGULAR')
    ->setFrequency('DAY')
    ->setFrequencyInterval('1')
    ->setCycles('1000')
    ->setAmount(new Currency(array(
        'value' => $request->paymentDefinition_0,
        'currency' => 'USD'
    )));
$paymentDefinition_1->setName('2nd Payment')
    ->setType('REGULAR')
    ->setFrequency('DAY')
    ->setFrequencyInterval('1')
    ->setCycles('1000')
    ->setAmount(new Currency(array(
        'value' => $request->paymentDefinition_1,
        'currency' => 'USD'
    )));

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM