cancel
Showing results for 
Search instead for 
Did you mean: 

Integrating PayPal Plus with REST API

Integrating PayPal Plus with REST API

Hallo,

i need some help with the code by integrating PayPal Plus with REST API. I have read the PayPal PDF, but it don't work or i don't understand.

At the end, the customer shall select the pay method!

 

(If i redirect after the call to PayPal, then the pay method is PayPal.)

 

Here is my PayPal Plus method (is an modified example from paypal):

    public static function paypalplus()
    {
        // Set clientId and secret
        self::loadPayment();

        $payer = new PayPal\Api\Payer();
        $payer->setPaymentMethod("paypal");

        $item1 = new PayPal\Api\Item();
        $item1->setName('Ground Coffee 40 oz')
            ->setDescription('Ground Coffee 40 oz')
            ->setCurrency('EUR')
            ->setQuantity(1)
            ->setTax(0.3)
            ->setPrice(7.50);

        $itemList = new PayPal\Api\ItemList();
        $itemList->setItems(array($item1));

        $details = new PayPal\Api\Details();
        $details->setShipping(1.2)
            ->setTax(0.3)
            ->setSubtotal(7.5);

        $amount = new PayPal\Api\Amount();
        $amount->setCurrency("EUR")
            ->setTotal(9)
            ->setDetails($details);

        $transaction = new PayPal\Api\Transaction();
        $transaction->setAmount($amount)
            ->setItemList($itemList)
            ->setDescription("Payment description.");

        $baseUrl = 'http://mypage.com';
        $redirectUrls = new PayPal\Api\RedirectUrls();
        $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
            ->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");

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

        $request = clone $payment;

        try {
            $result = $payment->create(self::$apiContext);
        } catch (Exception $ex) {
            echo 'Authorize a Payment';
            var_dump($payment->getId(), $ex);
            exit(1);
        }

        echo 'Authorize a Payment ID: ' . $payment->getId();
        echo "<br><br>";

        $redirectUrl = "";
        foreach ($payment->getLinks() as $link) {
            if ($link->getRel() == 'approval_url')
                $redirectUrl = $link->getHref();
        }

        if (strlen($redirectUrl))
            echo '<a href="'.$redirectUrl.'">'.$redirectUrl.'</a>';

        // $transactions = $payment->getTransactions();
        // $relatedResources = $transactions[0]->getRelatedResources();

        // var_dump($result);
        // $authorization = $relatedResources[0]->getAuthorization();
        //
        // var_dump($authorization);
    }

In the same PHP Requet (after the method call), i output the PayPal JavaScript (IFrame):

<script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js" type="text/javascript"></script>

<div id="ppplus"> </div>
<script type="application/javascript">
    var ppp = PAYPAL.apps.PPP({
        "approvalUrl": "http://beta.vintecture.com",
        "placeholder": "ppplus",
        "mode": "sandbox",
        "country": "DE"
    });
</script>

The IFrame respond is: "Sorry, at the moment no payments can be processed for technical reasons".

Is it normal, or my code is wrong.

 

Thanks

Konstantin

 

2 REPLIES
Highlighted
New Community Member

Re: Integrating PayPal Plus with REST API

Hi Konst,

 

I have the same problem. Take a look on the generated URL for the ppp.approvalUrl.

 

I see (in my case) a encoded URL like "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&amp;token=EC-...". The result was a iFrame like yours. After I decode the URL - it work.

 

OT: decode with JS -> https://stackoverflow.com/questions/1147359/how-to-decode-html-entities-using-jquery

 

Viele Grüsse

Dirk Smiley Happy

Member

Re: Integrating PayPal Plus with REST API

Hi,

 

any other solutions to the payment wall not displayed?

 

I've installed Paypal php SDK,  ceated payment and "Sorry, at the moment no payments can be processed for technical reasons" is my only result.

 

cheers thomas