2015-09-10 67 views
1

這是場景,用戶實例化一個貝寶交易(例如100美元),但返回到網站而不從貝寶取消並決定選擇不同的金額(例如25美元)。當它重定向到PayPal時,它仍然收費100美元。有沒有更新這個數量的方法?Paypal:交易實例化後的金額變化

//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); 
+2

你不能更新你傳遞到PayPal正確 –

+0

你是正確的金額。我正在將它存儲在會話中,原因是它搞亂了。謝謝 –

+0

Asif,您可以將解決方案添加到「您的答案」部分,以便其他人可以瞭解您學到了什麼?我在代碼中沒有看到關於$ _SESSION全局的任何內容,所以上面提供的答案並不能說明您是如何解決問題的。 –

回答

0

FYI: 我節省了用戶$ transactionDetails的會議,這樣,當貝寶重定向回給我,我可以更新我的付款記錄。

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']){