简体   繁体   中英

paypal recurring payment with initial payment

Hello i m using paypal express checkout with the merchant sdk. I have implemented recurring payment using the integration manual, but the given example doesn m using paypal express checkout with the merchant sdk. I have implemented recurring payment using the integration manual, but the given example doesn t 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

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.

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