Paypal:事务实例化后更改金额

时间:2015-09-10 20:54:01

标签: php codeigniter paypal

这是场景,用户实例化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);

1 个答案:

答案 0 :(得分:0)

供参考: 我在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);

FIX

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