gpt4 book ai didi

php - Paypal:实例化交易后更改金额

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

在这种情况下,用户实例化了一个 paypal 交易(例如 100 美元),但没有从 paypal 取消并返回网站并决定选择不同的金额(例如 25 美元)。当它重定向到 Paypal 时,它仍然收取 100 美元。有什么方法可以更新该金额吗?

//CODE SNIPPET 
$transactionDetails = array(
"amount" => array(
"total" => $total,
"currency" => PAYPAL_CURRENCY
),
"description" => "Adding $".$total.PAYPAL_CURRENCY
);
$returnUrl = site_url('referral/addFundForUser');
$cancelUrl = site_url('referral/');
$paymentMethod = "paypal";

$data = array(
"intent" => "sale",
"redirect_urls" => array(
"return_url" => $returnUrl,
"cancel_url" => $cancelUrl
),
"payer" => array(
"payment_method" => $paymentMethod
),
"transactions" => array($transactionDetails)
);


$header = array(
'Content-Type: application/json',
'Authorization: '.$tokenType. ' '.$accessToken
);



$url = $this->url.'v1/payments/payment';
return $this->doCurlCall($url,$data,$header);

最佳答案

仅供引用:我在 Session 中保存用户 $transactionDetails 以便当 paypal 重定向回我时,我可以更新我的付款日志。

if (!$this->getTransactionInfo() ){

$newTransaction = $this->paypal->startSale($this->getTokenType(),$this->getAccessToken(),$transactionDetails);
$transactionInfo = array(
"paymentTransactionId" => $newTransaction->id,
"total" => $total
);
foreach($newTransaction->links as $key=>$value){
if (strcmp($value->rel,'self') == 0){
$transactionInfo['self'] = $value->href;
}else if (strcmp($value->rel,'approval_url') == 0){
$transactionInfo['approval'] = $value->href;
$data['approval_url'] = $value->href;
}else if (strcmp($value->rel,'execute') == 0){
$transactionInfo['execute'] = $value->href;
}
}

$this->setTransactionInfo($transactionInfo,true);//SAVES IN SESSION
$paymentTransactionId = $newTransaction->id;
}else{

$newTransaction = $this->getTransactionInfo();
$paymentTransactionId = $newTransaction['paymentTransactionId'];
}


$successMsg = "Paypal Transaction Instantiated";

if ($this->insertPaymentLog($paymentTransactionId,$total,$payerId="",false,$successMsg,"",$transactionType)){

}
$data['transactionDetails'] = $transactionDetails;
$approval = $this->getTransactionInfo()['approval'];

redirect($approval);

修复

if (!$this->getTransactionInfo() || $total != $this->getTransactionInfo()['total']){

关于php - Paypal:实例化交易后更改金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32511411/

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