简体   繁体   中英

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

Already i tried this code but it's failed.

$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 and 30 are technically constants, you can't have them as names in form requests or access them as properties of objects, that's a syntax error

Either hardcode the values if they're constant

$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'
    )));

Or give them a string name in the HTML form and access that name as a property of the request object

For example

<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>

And access accordingly

$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'
    )));

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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