簡體   English   中英

magento-集成貝寶自適應支付(鏈式支付)

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

我目前正在將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個貝寶帳戶(賣方和網站的默認帳戶)和付款金額,並且正在尋求整合。

有沒有人以前集成過自適應支付,或者指出我應該在哪里集成這種邏輯? 我會覆蓋/ app / code / core / Mage / paypal中的功能之一嗎?

我基本上需要獲取當前購物車中的總成本以及當前商店的貝寶電子郵件,並將其傳遞給我的功能。

首先,您需要為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()."||";
}

您可能會忽略模塊流程,但可以按照以下步驟設置用於支付寶付款的沙盒帳戶,希望這會有所幫助

您可能需要為此編寫一個全新的付款模塊。 從我所看到的(並且我已經承認,自從詳細研究以來,已經有點過頭了),Magento中當前的PayPal集成不支持鏈式支付。

如果需要,您仍然可以擴展現有的PayPal模塊,但是您需要編寫API請求來相應地處理自適應支付調用。 同樣,沒有任何現有功能可以在擴展模塊中簡單地覆蓋。 您只需要從一開始就創建自己的。

如果最新版本的Magento添加了一些適應性付款,那么我可能會錯了。 如果是這種情況,您可能會在/ paypal目錄中直接引用該目錄,然后可以在其中研究函數以查看自己可以覆蓋的功能。 也就是說,如果他們已經將適應性付款包含在付款模塊中,那么您實際上就不需要在代碼中自定義它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM