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
6 REPLIES 6

Niederbobi
New Community Member

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 🙂

Login to Me Too

weinraum
Contributor
Contributor

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

Login to Me Too

mweber73
New Community Member

What is causing the problem? I have the same issue as described above

 

my javascriptcode for the payment-selection:

 

<script type="application/javascript">
var ppp = PAYPAL.apps.PPP({ 
"approvalUrl": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-123465766655",
    "placeholder": "ppplus",
    "country": "DE",
    "mode":"sandbox",
    "payerEmail":"test_at_myMail.de",
    "payerFirstName":"my",
    "payerLastName":"name",
    "payerTaxId":"",
    "language":"de_DE",
    });
</script>

I got the approvialURL from the PHP-SDK 

 

I get also JavaScript-Errors like

 

"Failed to load resource: the server responded with a status of 500 (Internal Server Error)" (by loading  https://www.sandbox.paypal.com/inlinepaymentwall/payment-selection)

 

and

 

"Refused to set the document's base URI to 'https://www.paypalobjects.com/web/res/fb5/81d00dad305f2f71ed3fa5dc43f86' because it violates the following Content Security Policy directive: "base-uri 'self' https://*.paypal.com"

 

 

Login to Me Too

fitpass
Contributor
Contributor

Did you find a solution? We are experiencing the same problem (base-uri error in "live" mode).

Login to Me Too

weinraum
Contributor
Contributor

Hi,

 

did you read Niederbobi answer?

 

Did you set all setups to live mode? online at paypal and your code?

 

set display errors on (paypal (!) and / or php)

cheers

thomas

 

 

 

 

Login to Me Too

CodoMg
Contributor
Contributor

I have the same Problem, on 2 separate instances (Wordpress and Shopware). 

 

Any fixes?

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.