cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

Integrating PayPal Plus with REST API

Konstantin-1
Contributor
Contributor

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

 

Login to Me Too
Who Me Too'd this topic