【问题标题】:Integrating Paypal chained/parallel payment with express checkout将 Paypal 链式/并行支付与快速结账相结合
【发布时间】:2016-03-11 19:29:58
【问题描述】:

我为预订系统制作了一个网络应用程序,并使用贝宝作为支付网关。使用贝宝快速结帐我可以付款,但现在我想在我作为服务提供商和受人尊敬的酒店之间按 5% : 95% 的比例分摊付款。如何在 php 中使用 express checkout 来实现这一点?

Paypal.config

     $currency = '$'; //Currency sumbol or code APP-80W284485P519543T

     //paypal settings sandbox
     $PayPalMode            = 'sandbox'; // sandbox or live
     $PayPalApiUsername     = 'email'; //PayPal API Username
     $PayPalApiPassword     = '1400209342'; //Paypal API password
     $PayPalApiSignature    = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AIicHs2L8N-aSaeIWzH3DX-kQJPv'; //Paypal API Signature
     $PayPalCurrencyCode    = 'USD'; //Paypal Currency Code
     $PayPalReturnURL       = returnURL; //Point to process.php page
     $PayPalCancelURL       = cancelURL; //Cancel URL if user clicks cancel

paypal.class

    class MyPayPal {

    public function PPHttpPost($methodName_, $nvpStr_, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode) {
        // Set up your API credentials, PayPal end point, and API version.
        $API_UserName = urlencode($PayPalApiUsername);
        $API_Password = urlencode($PayPalApiPassword);
        $API_Signature = urlencode($PayPalApiSignature);

        $paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';

        $API_Endpoint = "https://api-3t".$paypalmode.".paypal.com/nvp";
        $version = urlencode('109.0');

        // Set the curl parameters.
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);

        // Turn off the server and peer verification (TrustManager Concept).
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);

        // Set the API operation, version, and API signature in the request.
        $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

        // Set the request as a POST FIELD for curl.
        curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

        // Get response from the server.
        $httpResponse = curl_exec($ch);

        if(!$httpResponse) {
            exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
        }

        // Extract the response details.
        $httpResponseAr = explode("&", $httpResponse);

        $httpParsedResponseAr = array();
        foreach ($httpResponseAr as $i => $value) {
            $tmpAr = explode("=", $value);
            if(sizeof($tmpAr) > 1) {
                $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
            }
        }

        if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
            exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
        }

    return $httpParsedResponseAr;
  }

 }

和paypal支付方式

         $padata = '&METHOD=SetExpressCheckout' .
                    '&RETURNURL=' . urlencode($PayPalReturnURL) .
                    '&CANCELURL=' . urlencode($PayPalCancelURL) .
                    '&PAYMENTREQUEST_0_PAYMENTACTION=' . urlencode("SALE") .
                    $paypal_data .
                    '&NOSHIPPING=1' . //set 1 to hide buyer's shipping address, in-case products that does not require shipping
                    '&PAYMENTREQUEST_0_ITEMAMT=' . urlencode($ItemTotalPrice) .
                    '&PAYMENTREQUEST_0_SHIPPINGAMT=' . urlencode($ShippinCost) .
                    '&PAYMENTREQUEST_0_SHIPDISCAMT=' . urlencode($discount) .
                    '&PAYMENTREQUEST_0_AMT=' . urlencode($GrandTotal) .
                    '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($PayPalCurrencyCode) .
                    '&LOCALECODE=GB' . //PayPal pages to match the language on your website.
                    '&LOGOIMG=http://salyani.org/booking/contents/images/BookingBeta100PX.png' . //site logo
                    '&CARTBORDERCOLOR=FFFFFF' . //border color of cart
                    '&ALLOWNOTE=1';

【问题讨论】:

  • 为什么要关闭安全性? "关闭服务器和对等验证"

标签: php paypal


【解决方案1】:

可以使用 Express Checkout 进行并行付款,方法是在两次付款中分别包含主要和次要信息。更多详情here

但是,您不能通过快速结账进行连锁付款。 您需要查看 adaptive payments

您只需在您的 SEtexpress 结帐请求中包含以下示例请求。

METHOD=SetExpressCheckout                  
RETURNURL=http://example.com/success.html  
CANCELURL=http://example.com/canceled.html 
VERSION=93    
PAYMENTREQUEST_0_CURRENCYCODE=USD
PAYMENTREQUEST_0_AMT=250                            
PAYMENTREQUEST_0_ITEMAMT=225
PAYMENTREQUEST_0_TAXAMT=25
PAYMENTREQUEST_0_PAYMENTACTION=Order
PAYMENTREQUEST_0_DESC=Sunset Sail for Two
PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID=XXX@gmail.com  
PAYMENTREQUEST_0_PAYMENTREQUESTID=CART286-PAYMENT0    
L_PAYMENTREQUEST_0_NAME0=Departs Santa Cruz Harbor 
L_PAYMENTREQUEST_0_NUMBER0=Sunset Sail 22
L_PAYMENTREQUEST_0_QTY0=1                      

L_PAYMENTREQUEST_0_AMT0=225 
L_PAYMENTREQUEST_0_TAXAMT0=25                 


PAYMENTREQUEST_1_AMT=250                            
PAYMENTREQUEST_1_ITEMAMT=225
PAYMENTREQUEST_1_TAXAMT=25
PAYMENTREQUEST_1_PAYMENTACTION=Order
PAYMENTREQUEST_1_DESC=Sunset Sail for Two
PAYMENTREQUEST_1_SELLERPAYPALACCOUNTID=YYY.com  
PAYMENTREQUEST_1_PAYMENTREQUESTID=CART286-PAYMENT1    
L_PAYMENTREQUEST_1_NAME0=Departs Santa Cruz Harbor 
L_PAYMENTREQUEST_1_NUMBER0=Sunset Sail 22
L_PAYMENTREQUEST_1_QTY0=1                      

L_PAYMENTREQUEST_1_AMT0=225 
L_PAYMENTREQUEST_1_TAXAMT0=25  

【讨论】:

  • 谢谢@Vimalnath。我已经访问了上述链接,但我无法找到解决方案。您能否为我提供并行付款的出路?我怎样才能像上面的代码那样实现并行支付到两个不同的账户?
  • 报销总额错误显示为零。
  • 我使用了上面的参数,它可以工作。请确保您的请求是正确的。
猜你喜欢
  • 2013-07-15
  • 2011-12-03
  • 2018-04-15
  • 2011-05-25
  • 2017-02-22
  • 2014-04-15
  • 2013-05-17
  • 2013-09-28
  • 2011-08-06
相关资源
最近更新 更多