简体   繁体   English

magento-集成贝宝自适应支付(链式支付)

[英]magento - integrating paypal adaptive payments (chained payments)

I am currently working on integrating paypal's chained payment method into magento. 我目前正在将Paypal的链接式付款方式集成到magento中。 https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIntro https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIntro

The payment flow would be: buyer pays seller's paypal account -> pp adaptive payment gateway -> 85% goes to seller's paypal, 15% goes to site's default paypal account (buyer not aware of this split). 付款流程为:买方向卖方的Paypal帐户付款-> pp自适应付款网关-> 85%进入卖方的Paypal,15%进入站点的默认Paypal帐户(买方不知道此拆分)。

I already have the api function take takes 2 paypal accounts (seller's & site's default), and payment amount, and am looking to integrate this. 我已经有api函数,它需要2个贝宝帐户(卖方和网站的默认帐户)和付款金额,并且正在寻求整合。

Has anyone integrated adaptive payments before, or point me to where I should integrate this logic? 有没有人以前集成过自适应支付,或者指出我应该在哪里集成这种逻辑? Would I overwrite one of the functions in /app/code/core/Mage/paypal ? 我会覆盖/ app / code / core / Mage / paypal中的功能之一吗?

I basically need to get the total cost in the current shopping cart, and the paypal email of the current store, and pass that over to my function. 我基本上需要获取当前购物车中的总成本以及当前商店的贝宝电子邮件,并将其传递给我的功能。

First of all you need to create a seprate payment method for magento i would suggest to create a payment module for it after that you need to signup in to the paypal sandbox account . 首先,您需要为magento创建单独的付款方式,我建议您为此创建一个付款模块,然后再登录到paypal沙箱帐户。 i am attaching sample code for adaptive payment integration also some useful links for the flow how it will work 我附加了用于自适应支付集成的示例代码,还提供了一些有用的流程链接,以说明流程如何工作

ini_set("track_errors", true);
//set PayPal Endpoint to sandbox
$sandbox="";
$API_AppID = XXXXXXXXXXXXXXXXXXX;//your adaptive payment app Id
//value for check sandbox enable or disable
$sandboxstatus=1;
if($sandboxstatus==1){
    $sandbox="sandbox.";
    $API_AppID="APP-80W284485P519543T";
}
$url = trim("https://svcs.".$sandbox."paypal.com/AdaptivePayments/Pay");
//PayPal API Credentials
$API_UserName = XXXXXXXXXXXXXXXXXXX;//TODO
$API_Password = XXXXXXXXXXXXXXXXXXX;//TODO
$API_Signature = XXXXXXXXXXXXXXXXXXX;//TODO 
//Default App ID for Sandbox    
$API_RequestFormat = "NV";
$API_ResponseFormat = "NV";

$bodyparams = array (
    "requestEnvelope.errorLanguage" => "en_US",
    "actionType" => "PAY",
    "currencyCode" => "USD",//currency Code
    "cancelUrl" => "",// cancle url
    "returnUrl" => "paymentsuccess",//return url
    "ipnNotificationUrl" => "paymentnotify"//notification url that return all data related to payment
);

$finalcart=array(
        array('paypalid'=>"partner1",'price'=>50),
        array('paypalid'=>"partner2",'price'=>50),
        array('paypalid'=>"partner3",'price'=>50),
        array('paypalid'=>"partner4",'price'=>50),
        array('paypalid'=>"partner5",'price'=>50)
      );

$i=0;
foreach($finalcart as $partner){
    $temp=array("receiverList.receiver($i).email"=>$partner['paypalid'],"receiverList.receiver($i).amount"=>$partner['price']);
    $bodyparams+=$temp; 
    $i++;
}

// convert payload array into url encoded query string
$body_data = http_build_query($bodyparams, "", chr(38));
try{
   //create request and add headers
   $params = array("http" => array( 
      "method" => "POST",
      "content" => $body_data,
      "header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" .
                     "X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" .
                     "X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" .
                     "X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" .
                     "X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" .
                     "X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat . "\r\n"
   ));
   //create stream context
   $ctx = stream_context_create($params);
   //open the stream and send request
   $fp = @fopen($url, "r", false, $ctx);
   //get response
   $response = stream_get_contents($fp);
   //check to see if stream is open
   if ($response === false) {
      throw new Exception("php error message = " . "$php_errormsg");
   }
   //close the stream
   fclose($fp);
   //parse the ap key from the response
   $keyArray = explode("&", $response);
   foreach ($keyArray as $rVal){
       list($qKey, $qVal) = explode ("=", $rVal);
       $kArray[$qKey] = $qVal;
   }
   //set url to approve the transaction
   $payPalURL = "https://www.".$sandbox."paypal.com/webscr?cmd=_ap-payment&paykey=" . $kArray["payKey"];
   //print the url to screen for testing purposes
   If ( $kArray["responseEnvelope.ack"] == "Success") {
    echo '<p><a id="paypalredirect" href="' . $payPalURL . '"> Click here if you are not redirected within 10 seconds...</a> </p>';
    echo '<script type="text/javascript"> 
            function redirect(){
           document.getElementById("paypalredirect").click();
            }
            setTimeout(redirect, 2000);
              </script>';
   }
   else {
     echo 'ERROR Code: ' .  $kArray["error(0).errorId"] . " <br/>";
     echo 'ERROR Message: ' .  urldecode($kArray["error(0).message"]) . " <br/>";
  }
}
catch(Exception $e) {
    echo "Message: ||" .$e->getMessage()."||";
}

you may ignore the module flow but you can follow the steps for setting up the sandbox account for paypal payment hope it will help 您可能会忽略模块流程,但可以按照以下步骤设置用于支付宝付款的沙盒帐户,希望这会有所帮助

You're probably going to need to write a completely new payment module for that. 您可能需要为此编写一个全新的付款模块。 From what I've seen (and I'll admit it's been a little bit since I've looked at it in detail) the current PayPal integration in Magento does not support chained payments. 从我所看到的(并且我已经承认,自从详细研究以来,已经有点过头了),Magento中当前的PayPal集成不支持链式支付。

You could still extend the existing PayPal module(s) if you want, but you'll need to write the API requests to handle the adaptive payments calls accordingly. 如果需要,您仍然可以扩展现有的PayPal模块,但是您需要编写API请求来相应地处理自适应支付调用。 Again, there aren't any existing functions that you would simply override in your extended module. 同样,没有任何现有功能可以在扩展模块中简单地覆盖。 You'll just need to create your own from the start. 您只需要从一开始就创建自己的。

If the latest version of Magento added some adaptive payments then I could be wrong on that. 如果最新版本的Magento添加了一些适应性付款,那么我可能会错了。 If that's the case, you'd probably see something in the /paypal directory directly referring to it, and you can study the functions in there to see what you could override with your own. 如果是这种情况,您可能会在/ paypal目录中直接引用该目录,然后可以在其中研究函数以查看自己可以覆盖的功能。 That said, if they've already adaptive payments included as a payment module then you really shouldn't need to customize it in code. 也就是说,如果他们已经将适应性付款包含在付款模块中,那么您实际上就不需要在代码中自定义它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM