gpt4 book ai didi

php - magento - 集成 paypal 自适应支付(链式支付)

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:19 24 4
gpt4 key购买 nike

我目前正致力于将 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 电子邮件,并将其传递给我的函数。

最佳答案

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

您可以忽略模块流程,但您可以按照以下步骤设置 Paypal 支付的沙箱帐户,希望对您有所帮助

关于php - magento - 集成 paypal 自适应支付(链式支付),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13422250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com