Paypal Adaptive payment minibrowser

2019-08-06 09:44发布

I'm trying to use Paypal adaptive payment using mini browser option using Codeigniter framework in PHP for my products. When I click on pay button, the mini browser opens nice but when I click on Login buttons new tab opens but I want to open this login open in existing mini browser.

The view file:

       <html>
       <head>
       <script src="https://www.paypalobjects.com/js/external/apdg.js" type="text/javascript"></script>
     </head>
     <body>
      <?php echo form_open_multipart('pay/splitPay','target="PPDGFrame"', 'class="standard"', 'id="mini-form"'); ?>
  <label for="buy">Buy Now:</label>
     <input type="image" id="submitBtn" value="Pay with PayPal" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif">
    <input id="type" type="hidden" name="expType" value="mini">
    <input id="paykey" type="hidden" name="paykey" value="10">
    </form>
     <script type="text/javascript" charset="utf-8">
        var returnFromPayPal = function(){

        alert("Returned from PayPal");
     // Here you would need to pass on the payKey to your server side handle to call the PaymentDetails API to make sure Payment has been successful or not
  // based on the payment status- redirect to your success or cancel/failed urls
      }
     var dgFlowMini = new PAYPAL.apps.DGFlowMini({trigger: 'submitBtn', expType: 'mini', callbackFunction: 'returnFromPayPal'});
     </script>

the controller :

     function splitPay() {
       $createPacket = array (
        "actionType" => "PAY",
        "currencyCode" => 'USD',
        "receiverList" => array(
                "receiver" => array(
                    array("amount"=>'2.00', "email"=>'bhomnath@salyani.com.np'),
                    array("amount"=>'4.00', "email"=>'infotechnab_api1@yahoo.com'),
                )
            ),
        "returnUrl" => 'http://localhost/paypal/index.php/pay/notify_payment',
        "cancelUrl" => 'http://localhost/paypal/index.php/pay/tempo',
        "requestEnvelope" => $this->envelope
    );

    $response = $this->_paypalSend($createPacket,"Pay");
    $payKey = $response['payKey'];
    $detailsPacket = array(
        "requestEnvelope" => $this->envelope,
        "payKey" => $payKey,
        "receiverOptions" => array(
            array(
                "receiver"=>array(
                    'email'=>'bhomnath@salyani.com.np'),
                    'invoiceData'=>array(
                    'item'=>array(
                        array(
                            "name"=>'product1',
                            "price"=>'1.00',
                            "identifier"=>'P1'
                        ),
                        array(
                             "name"=>'product2',
                            "price"=>'1.00',
                            "identifier"=>'P2'
                        )
                    )
            )),
            array(
                "receiver"=>array(
                    'email'=>'infotechnab_api1@yahoo.com'),
                    'invoiceData'=>array(
                    'item'=>array(
                        array(
                            "name"=>'product3',
                            "price"=>'2.00',
                            "identifier"=>'P1'
                        ),
                        array(
                             "name"=>'product4',
                            "price"=>'2.00',
                            "identifier"=>'P2'
                        )
                    )
            ))
        )
    );

    $response = $this->_paypalSend($detailsPacket,"SetPaymentOptions");

    $dets = $this->getPaymentOptions($payKey);

    header("Location: ".$this->paypalUrl.$payKey);
}

1条回答
家丑人穷心不美
2楼-- · 2019-08-06 10:29

PayPal has security requirements that force a new window under some circumstances (and javascript to enforce this). Generally, they require this when the user is entering login credentials, which may be what you are referring to with the "login" vs "payment" button in your question?

This is done to minimize risk of credential theft through cross-site scripting attacks and to ensure the user sees the "chrome" (e.g. secure connection symbols and PayPal URL) and can verify the window is securely connected to PayPal when entering their credentials (for anti-phishing reasons).

Some of the newer PayPal products are relaxing these requirements, but I'm fairly certain Adaptive is solidly in this paradigm.

查看更多
登录 后发表回答