Using Objects in PAYPAL PHP REST API SDK

2020-08-01 05:15发布

问题:

I am new to Rest Api's . I am trying to create a payment using paypal express checkout via php sdk rest api.I have downloaded and installed their official sdk.

Now I can create a normal payment and everything is working fine.Now I want to set landing page type to billing.In documentation page I have been told to set landing_page_type to billing. How can I do that in my php script.

Link : https://developer.paypal.com/docs/api/#flowconfig-object

My php script looks something like

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription("Payment description")
    ->setInvoiceNumber(uniqid());



    $payment = new Payment();
    $payment->setIntent("sale")
        ->setPayer($payer)
        ->setRedirectUrls($redirectUrls)
        ->setTransactions(array($transaction));

    $payment->create($apiContext);

So As for I understood ,I must create new object named flow config and add landing page to it.I tried something like

    $billing = new FlowConfig();
$billing->setLandingPageType("billing");

What to do next ? How to integrage this $billing in my $payment

回答1:

To set landing page type, you should create a Payment Experience and specify the landing page in the request:

https://developer.paypal.com/docs/integration/direct/rest-experience-overview/ https://developer.paypal.com/docs/api/#payment-experience

PHP SDK sample: https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payment-experience/CreateWebProfile.php

There is a payment experience profile ID in the response. Then add the ExperienceProfileId to the request of Create a Payment like below:

$payment->setIntent("sale")
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));
    ->setExperienceProfileId(**********)