magento - 整合paypal自适应支付(链式支付)

时间:2012-11-16 18:21:56

标签: php magento paypal

我目前正致力于将paypal的链式付款方式整合到magento中。 https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIntro

付款流程如下: 买方支付卖方的paypal帐户 - > pp自适应支付网关 - > 85%用于卖家的PayPal,15%用于网站的默认paypal帐户(买家不知道这种拆分)。

我已经拥有api功能需要2个paypal帐户(卖家和网站的默认帐户)和付款金额,我希望整合这个。

之前有没有人整合过自适应支付,或者指出我应该在哪里整合这个逻辑?我会覆盖/ app / code / core / Mage / paypal中的一个功能吗?

我基本上需要获取当前购物车中的总费用,以及当前商店的paypal电子邮件,并将其传递给我的功能。

2 个答案:

答案 0 :(得分:1)

首先,您需要为magento创建一个单独的付款方式,我建议您在需要注册paypal沙盒帐户后为其创建付款模块。我正在附加自适应支付集成的示例代码以及流程的一些有用链接

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()."||";
}

您可以忽略模块流程,但是您可以按照设置沙盒帐户的步骤付款,希望能帮助

答案 1 :(得分:0)

您可能需要为此编写一个全新的付款模块。从我所看到的(并且我承认自从我详细研究它以来它已经有点了),目前在Magento中的PayPal集成不支持链式支付。

如果需要,您仍然可以扩展现有的PayPal模块,但您需要编写API请求以相应地处理自适应支付调用。同样,您不会在扩展模块中简单地覆盖任何现有功能。你只需要从一开始就创建自己的。

如果最新版本的Magento添加了一些自适应支付,那么我就错了。如果是这种情况,你可能会在/ paypal目录中看到一些直接引用它的东西,你可以在那里学习这些函数来查看你可以用你自己覆盖的内容。也就是说,如果他们已经将自适应支付作为支付模块包含在内,那么您真的不需要在代码中自定义它。

相关问题