Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal set unlimited cycles for recurring payments

I am trying to integrate the Paypal recurring payments for my mobile app. So far I managed to implement Paypal payments on various PHP apps using using https://github.com/paypal/PayPal-PHP-SDK, but this is the first time I am implementing recurring payments

I am trying to build the payment for the billing plan using the following code:

        $paymentDefinition = new PaymentDefinition();
        $paymentDefinition->setName('Mobile App subscription')
            ->setType('REGULAR')
            ->setFrequency('Month')
            ->setFrequencyInterval("1")
            ->setCycles("1")
            ->setAmount(
                new Currency(
                    array(
                        'value' => 50, 
                        'currency' => 'USD'
                    )
                )
            );

From the Paypal documentation, I understood that "setCycles" should be set to 0 for unlimited subscriptions. Setting it to 0 using the PHP SDK returns a 400 error.

Everything looks fine and I am receiving the first payment, but I am not sure that setting the Cycle to "1" will do the job I am looking for.

like image 730
Mishu Vlad Avatar asked Jan 09 '23 23:01

Mishu Vlad


1 Answers

I had the same problem, my solution was to just remove the setCylcles altogther, see here an example of how the plan and payment definition classes should look:

$plan = new Plan();
    $plan->setName('Some example name')
        ->setDescription('A short description of the plan')
        ->setType('INFINITE');

$paymentDefinition = new PaymentDefinition();
    $paymentDefinition->setName('Regular Payments')
        ->setType('REGULAR')
        ->setFrequency('Month')
        ->setFrequencyInterval("1")
        ->setAmount(new Currency(array('value' => 100, 'currency' => 'USD')));enter code here
like image 152
Jab73 Avatar answered Jan 11 '23 11:01

Jab73