2
votes

Hello im using paypal express checkout with the merchant sdk. I have implemented recurring payment using the integration manual, but the given example doesnt make an initial payment(charge the user right away). My code for making the payment is:

Initializing the payment:

    $cart = $this->cart->getCart();
    $items = $cart['items'];
    $itemTotal = 0;

    foreach ($items as $k => $item) {
        $product = $this->addItem($item);
        $itemTotal += $product->Amount;
        $this->paymentDetails->PaymentDetailsItem[$k] = $product;
    }

    $this->orderTotal->currencyID = 'USD';
    $this->orderTotal->value = $this->cart->getCartAmount();

    $this->paymentDetails->OrderTotal = $this->orderTotal;
    $this->paymentDetails->PaymentAction = 'Sale';
    $this->paymentDetails->InvoiceID = $invoice_id->{'$id'};

    $setECReqDetails = new \PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
    $setECReqDetails->PaymentDetails[0] = $this->paymentDetails;
    $setECReqDetails->CancelURL = $this->cancelURL;

    $setECReqDetails->ReturnURL = $this->returnURL;

    $billingAgreementDetails = new \PayPal\EBLBaseComponents\BillingAgreementDetailsType('RecurringPayments');
    $billingAgreementDetails->BillingAgreementDescription = 'recurringbilling';
    $setECReqDetails->BillingAgreementDetails = array($billingAgreementDetails);

    $setECReqType = new \PayPal\PayPalAPI\SetExpressCheckoutRequestType();
    $setECReqType->Version = $this->version;
    $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;

    $setECReq = new \PayPal\PayPalAPI\SetExpressCheckoutReq();
    $setECReq->SetExpressCheckoutRequest = $setECReqType;

    return $this->paypalService->SetExpressCheckout($setECReq);

And then on the return url i supplied i create the recurring payment with this code:

$profileDetails = new \PayPal\EBLBaseComponents\RecurringPaymentsProfileDetailsType();
    $profileDetails->BillingStartDate = "2014-01-24T00:00:00:000Z";

    $paymentBillingPeriod = new \PayPal\EBLBaseComponents\BillingPeriodDetailsType();
    $paymentBillingPeriod->BillingFrequency = 10;
    $paymentBillingPeriod->BillingPeriod = "Day";
    $paymentBillingPeriod->Amount = new \PayPal\CoreComponentTypes\BasicAmountType("USD", "1.0");
    $scheduleDetails = new \PayPal\EBLBaseComponents\ScheduleDetailsType();
    $activationDetails = new \PayPal\EBLBaseComponents\ActivationDetailsType();
    $activationDetails->InitialAmount = new \PayPal\CoreComponentTypes\BasicAmountType('USD', 49);
    $activationDetails->FailedInitialAmountAction = 'ContinueOnFailure';
    $scheduleDetails->Description = "recurringbilling";
    $scheduleDetails->ActivationDetails = $activationDetails;
    $scheduleDetails->PaymentPeriod = $paymentBillingPeriod;

    $createRPProfileRequestDetails = new \PayPal\EBLBaseComponents\CreateRecurringPaymentsProfileRequestDetailsType();
    $createRPProfileRequestDetails->Token = $token;

    $createRPProfileRequestDetails->ScheduleDetails = $scheduleDetails;
    $createRPProfileRequestDetails->RecurringPaymentsProfileDetails = $profileDetails;

    $createRPProfileRequest = new \PayPal\PayPalAPI\CreateRecurringPaymentsProfileRequestType();
    $createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetails;

    $createRPProfileReq = new \PayPal\PayPalAPI\CreateRecurringPaymentsProfileReq();
    $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;

    return $this->paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
}

In my sandbox account i can see that the recurring payment is created, but there is no initial payment. My question is: How can i setup this recurring payment, so that an initial payment is made?

Hope i`ve explained good my problem. If you need more information comment.

EIDT: My question was how to create a recurring payment with initial payment. and i edited my code snippet. After some reading i saw that i missed to set it up with setting "ActivationDetailsType". I set it up and it works fine with one problem ... The payment profile is pending for 4-5 hours and then comes through. I read in forums and etc... that this was a sandbox issue but unfortunetly i cannot be sure that the payment will not be deleyd. In my case i need the payment to be approved right away. My new question is, when creating recurring payment profile, and the response for the account is ok(succes or what not) and the profile is pending can i count the payment as successful and be sure i`ll get the money for sure

Thank you for the time. Regards, Georgi

1
I don't see the actual initial payment parameters in your request. Are you sure that's what you mean, or are you just talking about the first payment on the profile that should come through? An actual "initial payment" would be a one-time payment separate from the profile that you can charge upon profile creation. Like a setup fee for a cable subscription, for example. Please confirm that and post a sample of your actual API request as opposed to the code that's generating it.Drew Angell

1 Answers

0
votes

Quite late but I'm having similar concerns.

My new question is, when creating recurring payment profile, and the response for the account is ok(succes or what not) and the profile is pending can i count the payment as successful and be sure i`ll get the money for sure?

I'm currently working on it but I wouldn't count the pay until PayPal reflects the payment. I would utilize the IPN to trigger actions that should be made when the payment has come through. As for the 4-5 hour processing by PayPal (though sources from the web say production should not have the same delay), I'll just be sure to notify the buyer that his/her payment is still being processed by PayPal.