2012-11-16 134 views
0

我目前正在將paypal的鏈式支付方法整合到magento中。 https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIntromagento - 整合支付寶適應性支付(連鎖支付)

付款流程將是: 買方支付賣方的PayPal賬戶 - > PP自適應支付網關 - > 85%到賣家的貝寶,15%用於站點的默認PayPal帳戶(買方不知道這種分裂的)。

我已經有api功能採取2 paypal帳戶(賣方的&網站的默認值),和支付金額,並希望整合這一點。

有沒有人在之前整合過適應性支付,或者指出我應該在哪裏整合這種邏輯?我會覆蓋/ app/code/core/Mage/paypal中的某個函數嗎?

我基本上需要獲得當前購物車和當前商店的PayPal電子郵件的總成本,並將其傳遞給我的函數。

回答

0

您可能需要爲此編寫一個全新的付款模塊。從我所看到的情況(我承認自從我仔細研究它之後已經有點了),Magento目前的PayPal集成不支持鏈式支付。

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

如果最新版本的Magento添加了一些適應性付款,那麼我可能會錯。如果是這樣的話,你可能會直接在/ paypal目錄中看到一些東西,你可以在那裏研究這些功能,看看你可以用你自己的東西來覆蓋。也就是說,如果他們已經將適應性支付作爲支付模塊包含在內,那麼您確實不需要在代碼中對其進行定製。

+0

感謝您的輸入安德魯,從它的聲音,它不會是一個現有的貝寶功能之一的直接定製。我將不得不更多關注本地magento支付(網關重定向,退款,cc拒絕等)功能。 – kkuni

+0

是的,我只是覺得他們還沒有鏈接,但我相信他們正在努力。我知道這是人們想要的流行功能,而且他們現在擁有Magento,所以你會認爲他們會盡早完成,而不是晚些時候完成。我發現自己陷入了這種介於兩者之間的狀態,有很多事情。如果他們很快就要開發自己的定製模塊,我不想花時間去構建自己的定製模塊,但我也不想等上幾個月。很難決定有時要做什麼。 –

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

你可以忽略模塊流量,但你可以按照設置沙箱帳戶支付寶付款的步驟希望將有助於