当前位置: 首页 > 知识库问答 >
问题:

Paypal Express结账API付款后不收费

能远
2023-03-14

我正在使用Paypal Express Checkout API来处理Paypal和VISA付款。
我的代码将用户重定向到Paypal页面,并在提交表单后进行身份验证。然后我继续进行身份验证,并单击立即支付按钮。
我被重定向到返回网址。显然一切似乎都很好,但我从未在资本账户上收到过钱,也从未从买家账户中收取过钱。

以下是我请求令牌的代码:

private function _proceed_to_paypal($total_amount = false, $id_order = false, $description = false) {

    if ($total_amount === false || $id_order === false) {
        return false;
    }

    $this->load->library('paypal_functions');

    $this->paypal_functions->init();

    // ==================================
    // PayPal Express Checkout Module
    // ==================================

    //'------------------------------------
    //' The paymentAmount is the total value of 
    //' the shopping cart, that was set 
    //' earlier in a session variable 
    //' by the shopping cart page
    //'------------------------------------
    $paymentAmount = $total_amount;

    //'------------------------------------
    //' The currencyCodeType and paymentType 
    //' are set to the selections made on the Integration Assistant 
    //'------------------------------------
    $currencyCodeType = "EUR";
    $paymentType = "Sale";

    //'------------------------------------
    //' The returnURL is the location where buyers return to when a
    //' payment has been succesfully authorized.
    //'
    //' This is set to the value entered on the Integration Assistant 
    //'------------------------------------
    $returnURL = site_url('payment/success');

    //'------------------------------------
    //' The cancelURL is the location buyers are sent to when they hit the
    //' cancel button during authorization of payment during the PayPal flow
    //'
    //' This is set to the value entered on the Integration Assistant 
    //'------------------------------------
    $cancelURL = site_url('payment/cancel');

    //'------------------------------------
    //' Calls the SetExpressCheckout API call
    //'
    //' The CallShortcutExpressCheckout function is defined in the file PayPalFunctions.php,
    //' it is included at the top of this file.
    //'-------------------------------------------------
    $resArray = $this->paypal_functions->CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $description);
    $ack = strtoupper($resArray["ACK"]);
    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING") {
        $this->paypal_functions->RedirectToPayPal($resArray["TOKEN"]);
    } else  {


        $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
        $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
        $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
        $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);

        echo "SetExpressCheckout API call failed. ";
        echo '<br />';
        echo "Detailed Error Message: " . $ErrorLongMsg;
        echo '<br />';
        echo "Short Error Message: " . $ErrorShortMsg;
        echo '<br />';
        echo "Error Code: " . $ErrorCode;
        echo '<br />';
        echo "Error Severity Code: " . $ErrorSeverityCode;
        echo '<br />';
    }

}

paypal_函数库:

<?php (defined('BASEPATH')) OR exit('No direct script access allowed');


class Paypal_functions { 


private $PROXY_HOST = '127.0.0.1';
private $PROXY_PORT = '808';

// signals the test mode
private $SandboxFlag = false;


/* Paypal credentials */ 
private $API_UserName="xxx";
private $API_Password="xxx";
private $API_Signature="xxx";


// BN Code  is only applicable for partners
private $sBNCode = "PP-ECWizard";

private $USE_PROXY = false;
private $version = 0;

private $API_Endpoint;
private $PAYPAL_URL;


private $gv_ApiErrorURL;






/*  
' Define the PayPal Redirect URLs.  
'   This is the URL that the buyer is first sent to do authorize payment with their paypal account
'   change the URL depending if you are testing on the sandbox or the live PayPal site
'
' For the sandbox, the URL is       https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
' For the live site, the URL is        https://www.paypal.com/webscr&cmd=_express-checkout&token=
*/

public function init() {
    if ($this->SandboxFlag == true) {
        $this->API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
        $this->PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
    } else {
        $this->API_Endpoint = "https://api-3t.paypal.com/nvp";
        $this->PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
    }

    $this->USE_PROXY = false;
    $this->version= "93";


}



/* An express checkout transaction starts with a token, that
   identifies to PayPal your transaction
   In this example, when the script sees a token, the script
   knows that the buyer has already authorized payment through
   paypal.  If no token was found, the action is to send the buyer
   to PayPal to first authorize payment
   */

/*   
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose:  Prepares the parameters for the SetExpressCheckout API Call.
' Inputs:  
'       paymentAmount:      Total value of the shopping cart
'       currencyCodeType:   Currency code value the PayPal API
'       paymentType:        paymentType has to be one of the following values: Sale or Order or Authorization
'       returnURL:          the page where buyers return to after they are done with the payment review on PayPal
'       cancelURL:          the page where buyers return to when they cancel the payment review on PayPal
'--------------------------------------------------------------------------------------------------------------------------------------------   
*/
public function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $description) {
    //------------------------------------------------------------------------------------------------------------------------------------
    // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation

    $nvpstr="&PAYMENTREQUEST_0_AMT=". $paymentAmount;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
    $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
    $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;

    $nvpstr = $nvpstr . "&SOLUTIONTYPE=" . 'Sole';
    $nvpstr = $nvpstr . "&LANDINGPAGE=" . 'Billing';

    //'--------------------------------------------------------------------------------------------------------------- 
    //' Make the API call to PayPal
    //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.  
    //' If an error occured, show the resulting errors
    //'---------------------------------------------------------------------------------------------------------------
    $resArray = $this->hash_call("SetExpressCheckout", $nvpstr);
    $ack = strtoupper($resArray["ACK"]);
    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
    {
        $token = urldecode($resArray["TOKEN"]);
        $_SESSION['TOKEN']=$token;
    }

    return $resArray;
}

/*   
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose:  Prepares the parameters for the SetExpressCheckout API Call.
' Inputs:  
'       paymentAmount:      Total value of the shopping cart
'       currencyCodeType:   Currency code value the PayPal API
'       paymentType:        paymentType has to be one of the following values: Sale or Order or Authorization
'       returnURL:          the page where buyers return to after they are done with the payment review on PayPal
'       cancelURL:          the page where buyers return to when they cancel the payment review on PayPal
'       shipToName:     the Ship to name entered on the merchant's site
'       shipToStreet:       the Ship to Street entered on the merchant's site
'       shipToCity:         the Ship to City entered on the merchant's site
'       shipToState:        the Ship to State entered on the merchant's site
'       shipToCountryCode:  the Code for Ship to Country entered on the merchant's site
'       shipToZip:          the Ship to ZipCode entered on the merchant's site
'       shipToStreet2:      the Ship to Street2 entered on the merchant's site
'       phoneNum:           the phoneNum  entered on the merchant's site
'--------------------------------------------------------------------------------------------------------------------------------------------   
*/
public function CallMarkExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, 
                                  $cancelURL, $shipToName, $shipToStreet, $shipToCity, $shipToState,
                                  $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum
                                ) {
    //------------------------------------------------------------------------------------------------------------------------------------
    // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation

    $nvpstr="&PAYMENTREQUEST_0_AMT=". $paymentAmount;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
    $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
    $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;
    $nvpstr = $nvpstr . "&ADDROVERRIDE=1";
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTONAME=" . $shipToName;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTOSTREET=" . $shipToStreet;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTOSTREET2=" . $shipToStreet2;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTOCITY=" . $shipToCity;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTOSTATE=" . $shipToState;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=" . $shipToCountryCode;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTOZIP=" . $shipToZip;
    $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPTOPHONENUM=" . $phoneNum;

    $_SESSION["currencyCodeType"] = $currencyCodeType;    
    $_SESSION["PaymentType"] = $paymentType;

    //'--------------------------------------------------------------------------------------------------------------- 
    //' Make the API call to PayPal
    //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.  
    //' If an error occured, show the resulting errors
    //'---------------------------------------------------------------------------------------------------------------
    $resArray=hash_call("SetExpressCheckout", $nvpstr);
    $ack = strtoupper($resArray["ACK"]);
    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
    {
        $token = urldecode($resArray["TOKEN"]);
        $_SESSION['TOKEN']=$token;
    }

    return $resArray;
}

/*
'-------------------------------------------------------------------------------------------
' Purpose:  Prepares the parameters for the GetExpressCheckoutDetails API Call.
'
' Inputs:  
'       None
' Returns: 
'       The NVP Collection object of the GetExpressCheckoutDetails Call Response.
'-------------------------------------------------------------------------------------------
*/
public function GetShippingDetails( $token ) {
    //'--------------------------------------------------------------
    //' At this point, the buyer has completed authorizing the payment
    //' at PayPal.  The function will call PayPal to obtain the details
    //' of the authorization, incuding any shipping information of the
    //' buyer.  Remember, the authorization is not a completed transaction
    //' at this state - the buyer still needs an additional step to finalize
    //' the transaction
    //'--------------------------------------------------------------

    //'---------------------------------------------------------------------------
    //' Build a second API request to PayPal, using the token as the
    //'  ID to get the details on the payment authorization
    //'---------------------------------------------------------------------------
    $nvpstr="&TOKEN=" . $token;

    //'---------------------------------------------------------------------------
    //' Make the API call and store the results in an array.  
    //' If the call was a success, show the authorization details, and provide
    //'     an action to complete the payment.  
    //' If failed, show the error
    //'---------------------------------------------------------------------------
    $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);
    $ack = strtoupper($resArray["ACK"]);
    if($ack == "SUCCESS" || $ack=="SUCCESSWITHWARNING")
    {   
        $_SESSION['payer_id'] = $resArray['PAYERID'];
    } 
    return $resArray;
}

/*
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose:  Prepares the parameters for the GetExpressCheckoutDetails API Call.
'
' Inputs:  
'       sBNCode:    The BN code used by PayPal to track the transactions from a given shopping cart.
' Returns: 
'       The NVP Collection object of the GetExpressCheckoutDetails Call Response.
'--------------------------------------------------------------------------------------------------------------------------------------------   
*/
public function ConfirmPayment( $FinalPaymentAmt )
{
    /* Gather the information to make the final call to
       finalize the PayPal payment.  The variable nvpstr
       holds the name value pairs
       */


    //Format the other parameters that were stored in the session from the previous calls   
    $token              = urlencode($_SESSION['TOKEN']);
    $paymentType        = urlencode($_SESSION['PaymentType']);
    $currencyCodeType   = urlencode($_SESSION['currencyCodeType']);
    $payerID            = urlencode($_SESSION['payer_id']);

    $serverName         = urlencode($_SERVER['SERVER_NAME']);

    $nvpstr  = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTREQUEST_0_PAYMENTACTION=' . $paymentType . '&PAYMENTREQUEST_0_AMT=' . $FinalPaymentAmt;
    $nvpstr .= '&PAYMENTREQUEST_0_CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName; 

     /* Make the call to PayPal to finalize payment
        If an error occured, show the resulting errors
        */
    $resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);

    /* Display the API response back to the browser.
       If the response from PayPal was a success, display the response parameters'
       If the response was an error, display the errors received using APIError.php.
       */
    $ack = strtoupper($resArray["ACK"]);

    return $resArray;
}

/*
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose:  This function makes a DoDirectPayment API call
'
' Inputs:  
'       paymentType:        paymentType has to be one of the following values: Sale or Order or Authorization
'       paymentAmount:      total value of the shopping cart
'       currencyCode:       currency code value the PayPal API
'       firstName:          first name as it appears on credit card
'       lastName:           last name as it appears on credit card
'       street:             buyer's street address line as it appears on credit card
'       city:               buyer's city
'       state:              buyer's state
'       countryCode:        buyer's country code
'       zip:                buyer's zip
'       creditCardType:     buyer's credit card type (i.e. Visa, MasterCard ... )
'       creditCardNumber:   buyers credit card number without any spaces, dashes or any other characters
'       expDate:            credit card expiration date
'       cvv2:               Card Verification Value 
'       
'-------------------------------------------------------------------------------------------
'       
' Returns: 
'       The NVP Collection object of the DoDirectPayment Call Response.
'--------------------------------------------------------------------------------------------------------------------------------------------   
*/


public function DirectPayment( $paymentType, $paymentAmount, $creditCardType, $creditCardNumber,
                        $expDate, $cvv2, $firstName, $lastName, $street, $city, $state, $zip, 
                        $countryCode, $currencyCode )
{
    //Construct the parameter string that describes DoDirectPayment
    $nvpstr = "&AMT=" . $paymentAmount;
    $nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCode;
    $nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType;
    $nvpstr = $nvpstr . "&CREDITCARDTYPE=" . $creditCardType;
    $nvpstr = $nvpstr . "&ACCT=" . $creditCardNumber;
    $nvpstr = $nvpstr . "&EXPDATE=" . $expDate;
    $nvpstr = $nvpstr . "&CVV2=" . $cvv2;
    $nvpstr = $nvpstr . "&FIRSTNAME=" . $firstName;
    $nvpstr = $nvpstr . "&LASTNAME=" . $lastName;
    $nvpstr = $nvpstr . "&STREET=" . $street;
    $nvpstr = $nvpstr . "&CITY=" . $city;
    $nvpstr = $nvpstr . "&STATE=" . $state;
    $nvpstr = $nvpstr . "&COUNTRYCODE=" . $countryCode;
    $nvpstr = $nvpstr . "&IPADDRESS=" . $_SERVER['REMOTE_ADDR'];

    $resArray=hash_call("DoDirectPayment", $nvpstr);

    return $resArray;
}


/**
  * -------------------------------------------------------------------------------------------------------------------------------------------
  * hash_call: Function to perform the API call to PayPal using API signature
  * @methodName is name of API  method.
  * @nvpStr is nvp string.
  * returns an associtive array containing the response from the server.
  * -------------------------------------------------------------------------------------------------------------------------------------------
*/
public function hash_call($methodName,$nvpStr)
{
    //declaring of global variables
    /*
    global $API_Endpoint, $this->version, $API_UserName, $API_Password, $API_Signature;
    global $this->USE_PROXY, $PROXY_HOST, $PROXY_PORT;
    global $gv_ApiErrorURL;
    global $sBNCode;
    */

    //setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$this->API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    //turning off the server and peer verification(TrustManager Concept).
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);

    //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
   //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php 
    if($this->USE_PROXY)
        curl_setopt ($ch, CURLOPT_PROXY, $this->PROXY_HOST. ":" . $this->PROXY_PORT); 

    //NVPRequest for submitting to server
    $nvpreq="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($this->version) . "&PWD=" . urlencode($this->API_Password) . "&USER=" . urlencode($this->API_UserName) . "&SIGNATURE=" . urlencode($this->API_Signature) . $nvpStr . "&BUTTONSOURCE=" . urlencode($this->sBNCode);

    //setting the nvpreq as POST FIELD to curl
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    //getting response from server
    $response = curl_exec($ch);

    //convrting NVPResponse to an Associative Array
    $nvpResArray = $this->deformatNVP($response);
    $nvpReqArray = $this->deformatNVP($nvpreq);
    $_SESSION['nvpReqArray']=$nvpReqArray;

    if (curl_errno($ch)) 
    {
        // moving to display page to display curl errors
          //$_SESSION['curl_error_no']=curl_errno($ch) ;
          //$_SESSION['curl_error_msg']=curl_error($ch);

          //Execute the Error handling module to display errors. 
    } 
    else 
    {
         //closing the curl
        curl_close($ch);
    }

    return $nvpResArray;
}

/*'----------------------------------------------------------------------------------
 Purpose: Redirects to PayPal.com site.
 Inputs:  NVP string.
 Returns: 
----------------------------------------------------------------------------------
*/
public function RedirectToPayPal ( $token )
{
    //global $PAYPAL_URL;

    // Redirect to paypal.com here
    $payPalURL = $this->PAYPAL_URL . $token . '&useraction=commit';
    header("Location: ".$payPalURL);
    exit;
}


/*'----------------------------------------------------------------------------------
 * This function will take NVPString and convert it to an Associative Array and it will decode the response.
  * It is usefull to search for a particular key and displaying arrays.
  * @nvpstr is NVPString.
  * @nvpArray is Associative Array.
   ----------------------------------------------------------------------------------
  */
public  function deformatNVP($nvpstr)
{
    $intial=0;
    $nvpArray = array();

    while(strlen($nvpstr))
    {
        //postion of Key
        $keypos= strpos($nvpstr,'=');
        //position of value
        $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);

        /*getting the Key and Value values and storing in a Associative Array*/
        $keyval=substr($nvpstr,$intial,$keypos);
        $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
        //decoding the respose
        $nvpArray[urldecode($keyval)] =urldecode( $valval);
        $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
     }
    return $nvpArray;
}

}  

PS-这是之前回响$nvpstr的结果:

$resArray = $this->hash_call("SetExpressCheckout", $nvpstr);  

-

&PAYMENTREQUEST_0_AMT=0.01&
PAYMENTREQUEST_0_PAYMENTACTION=Sale&
RETURNURL=http://localhost/site/payment/success&
CANCELURL=http://localhost/site/payment/cancel&
PAYMENTREQUEST_0_CURRENCYCODE=EUR&
SOLUTIONTYPE=Sole&
LANDINGPAGE=Billing  

提前谢谢!

共有1个答案

黎奇思
2023-03-14

听起来你只是完成了过程的第一部分。Express Checkout包含3个单独的呼叫:

  • SetExpressCheckout

在您完成最终DoExpressCheckoutPayment呼叫之前,不会处理任何款项。

有关此方面的更多详细信息,请参阅《快速签出集成指南》。

 类似资料:
  • 说明api接口绑定收款账户 请求地址 http://api.dc78.cn/Api/sys_createCollectionAccount 请求方式 POST 请求参数 参数 参数名称 描述 account_id 收款账号ID 不传值则为新增,传值则为编辑(编辑只允许修改收款账号名称) pay_type 支付通道类型 1:微信 2:支付宝 3:扫呗 account_name 账号名称(账号名称只用

  • 我需要在贝宝中使用部分支付,但我不知道如何在PHP中使用贝宝部分支付。在没有信用卡的情况下使用贝宝账户授权和捕获金额的过程是什么。 例如,如果我在结账时授权1000美元,第一次发货时捕获500美元,第二次发货时捕获500美元。

  • 我对PayPal API和REST请求/响应非常陌生。因此,我一直在尝试跟随在线示例(主要来自GitHub),了解如何使用PayPal的RESTAPI来处理付款。 然而,我遇到了一个问题。当我点击生成的链接时,我被成功地重定向到贝宝的网站。但是,在结帐页面上,没有显示购买金额。问题可能是什么?谢谢

  • null null Merchant API:https://developer.paypal.com/webapps/developer/docs/classic/api/#Merchant 我很感激你的帮助。

  • 我正在实施贝宝结账。 我有以下javascript代码paypal.button.render({ 弹出(上图)出现时,我点击贝宝按钮,我可以填写信用卡细节等,如图像。它在沙箱所以我使用测试卡号。当我单击“立即付款”按钮时,它会显示“正在处理”,并一遍又一遍地返回到相同的表单。我现在可以在控制台或回调中看到信息 I.W希望看到我的警报 onauthorize:函数(数据,操作){