Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
paypal solutiontype=sole_Paypal - Fatal编程技术网

paypal solutiontype=sole

paypal solutiontype=sole,paypal,Paypal,我有一个网站,引导我的客户到贝宝快捷结帐。我想让客人选择付款而不创建贝宝帐户。我对paypal SetExpressCheckout API调用有两个变量,但无法在代码中找到它的位置。有人能帮我吗 变量和值: SOLUTIONTYPE=sole 登陆页面=计费 守则: <?php /** * PayPal class */ class PayPal { var $version = "64"; /** * Wether or not use Sandbox

我有一个网站,引导我的客户到贝宝快捷结帐。我想让客人选择付款而不创建贝宝帐户。我对paypal SetExpressCheckout API调用有两个变量,但无法在代码中找到它的位置。有人能帮我吗

变量和值:

SOLUTIONTYPE=sole 登陆页面=计费

守则:

<?php

/**
 * PayPal class
 */
class PayPal
{
    var $version = "64";

    /**
     * Wether or not use Sandbox mode
     */
    var $sandbox = false;

    /**
     * The API credentials
     */
    var $api_username;
    var $api_password;
    var $api_signature;

    /**
     * The API endpoint and the URL for non-sandbox integration
     */
    var $api_endpoint = 'https://api-3t.paypal.com/nvp';
    var $paypal_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=';

    /**
     * Proxy settings
     */
    var $use_proxy = false;
    var $proxy_host = '127.0.0.1';
    var $proxy_port = 808;

    /**
     * BN Code is only applicable for partners
     */
    var $bncode = "PP-ECWizard";

    /**
     * Some private keys
     */
    private $_token;
    private $_payerId;
    private $_currency = 'EUR';
    private $_paymentType = 'Sale';
    private $_resArray = array();

    /**
     * Constructor
     * @param string $api_username
     * @param string $api_password
     * @param string $api_signature
     */
    public function __construct($api_username, $api_password, $api_signature) {

        $this->api_username = $api_username;
        $this->api_password = $api_password;
        $this->api_signature = $api_signature;
    }

    /**
     * Set Sandbox status
     */
    public function useSandbox() {

        $this->sandbox = true;
        $this->api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
        $this->paypal_url = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=';
    }

    /**
     * When using a proxy server, set the host and port
     * @param string $host
     * @param integer $port
     */
    public function useProxy($host, $port=808) {

        if(!empty($host) && !empty($port) && is_numeric($port)) {

            $this->use_proxy = true;
            $this->proxy_host = $host;
            $this->proxy_port = (integer) $port;
        }
    }

    /**
     * Sets a new BN ocde
     */
    public function setBNcode($bncode=null) {

        $this->bncode = $bncode;
    }

    /**
     * Sets the currency used for the order
     */
    public function setCurrency($currency='EUR') {

        $this->_currency = $currency;
    }

    /**
     * The type of payment is done here
     */
    public function setPaymentType($type='Sale') {

        $this->_paymentType = $type;
    }

    /**
     * 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
     * 
     * Prepares the parameters for the SetExpressCheckout API Call.
     * 
     * @param string $paymentAmount:        Total value of the shopping cart
     * @param string $returnURL:            the page where buyers return to after they are done with the payment review on PayPal
     * @param string $cancelURL:            the page where buyers return to when they cancel the payment review on PayPal
    */
    function shortcutExpressCheckout($paymentAmount, $returnURL, $cancelURL) 
    {
        // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
        $nvpstr = '&PAYMENTREQUEST_0_AMT='. $paymentAmount;
        $nvpstr .= '&PAYMENTREQUEST_0_PAYMENTACTION='.$this->_paymentType;
        $nvpstr .= '&RETURNURL='.$returnURL;
        $nvpstr .= '&CANCELURL='.$cancelURL;
        $nvpstr .= '&PAYMENTREQUEST_0_CURRENCYCODE='.$this->_currency;

        // 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->_hashCall('SetExpressCheckout', $nvpstr);
        $ack = strtoupper($resArray["ACK"]);

        if($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING') {
            $this->_token = urldecode($resArray["TOKEN"]);
        }
        else {
            throw new PayPal_Exception($resArray['L_ERRORCODE0'].': '.$resArray['L_SHORTMESSAGE0'].', '.$resArray['L_LONGMESSAGE0']);
        }

        // save result
        $this->_resArray = $resArray;
    }

    /**
     * Sets a token for confirm purposes
     * @param string $token
     */
    public function setToken($token) {

        if(!empty($token)) {

            $this->_token = $token;
        }
    }

    /**
     * Returns the token set for the current payment
     * @return string
     */
    public function getToken() {

        return $this->_token;
    }

    /**
     * Sets the payer id for confirm purposes
     * @param string $payerid
     */
    public function setPayer($payerid) {

        if(!empty($payerid)) {

            $this->_payerId = $payerid;
        }
    }

    /**
     * Returns the result array set for the current payment
     * @return array
     */
    public function getResult() {

        return $this->_resArray;
    }

    /**
     * Prepares the parameters for the GetExpressCheckoutDetails API Call.
     *
     * @param string $paymentAmount:    The total payment amount.
     * @return object The NVP Collection object of the GetExpressCheckoutDetails Call Response.
     */
    function confirm($paymentAmount)
    {
        // Format the other parameters that were stored in the session from the previous calls
        $serverName = urlencode($_SERVER['SERVER_NAME']);

        $nvpstr = '&TOKEN='.urlencode($this->_token);
        $nvpstr .= '&PAYERID='.urlencode($this->_payerId);
        $nvpstr .= '&PAYMENTREQUEST_0_PAYMENTACTION='.$this->_paymentType;
        $nvpstr .= '&PAYMENTREQUEST_0_AMT='.$paymentAmount;
        $nvpstr .= '&PAYMENTREQUEST_0_CURRENCYCODE='.$this->_currency;
        $nvpstr .= '&IPADDRESS='.$serverName; 

        // Make the call to PayPal to finalize payment
        // if an error occured, show the resulting errors
        $resArray = $this->_hashCall('DoExpressCheckoutPayment', $nvpstr);

        $this->_resArray = $resArray;
    }

    /**
     * Function to perform the API call to PayPal using API signature
     * @param string $methodName:   is name of API  method.
     * @param string $nvpStr:       is nvp string.
     * @return array containing the response from the server.
     */
    private function _hashCall($methodName, $nvpStr)
    {
        // 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 set to TRUE, then only proxy will be enabled. 
        if($this->use_proxy) {

            curl_setopt ($ch, CURLOPT_PROXY, $this->proxy_host.':'.$this->proxy_port); 
        }

        // NVPRequest for submitting to server
        $nvpreq = 'METHOD='.urlencode($methodName);
        $nvpreq .= '&VERSION='.urlencode($this->version);
        $nvpreq .= '&PWD='.urlencode($this->api_password);
        $nvpreq .= '&USER='.urlencode($this->api_username);
        $nvpreq .= '&SIGNATURE='.urlencode($this->api_signature);
        $nvpreq .= $nvpStr.'&BUTTONSOURCE='.urlencode($this->bncode);

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

        // Execute the Error handling module to display errors.
        if(curl_errno($ch)) {

            $error = curl_error($ch);
            throw new PayPal_Exception($error);
        } 
        // closing the curl
        else {

            curl_close($ch);
        }

        return $nvpResArray;
    }

    /**
     * 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.
     * @param string $nvpstr is NVPString.
     * @return array $nvpArray is Associative Array.
     **/
    private 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;
    }

    /**
     * Redirects to PayPal.com site.
     */
    public function redirect() {

        $url = $this->paypal_url.$this->_token;
        header("Location: ".$url);
        exit();
    }
}

class PayPal_Exception extends Exception
{
    // Redefine the exception so message isn't optional
    public function __construct($message, $code = 0) {

        // make sure everything is assigned properly
        parent::__construct($message, $code);
    }

    // custom string representation of object
    public function __toString() {
        return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
    }
}

?>

无论您使用的是什么类库,它对Express Checkout的功能似乎都非常有限。它基本上是使用最简单的选项来实现的

您的
shortcutExpressCheckout()
仅接受3个参数:
$paymentAmount
$returnURL
,以及
$cancelURL
。这里面还有很多东西,包括你想要传递的选项

在该函数中,它们生成NVP字符串并将其分配给$nvpstr变量。这是您需要添加新参数以获得所需效果的地方

试试这个

// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
$nvpstr = '&PAYMENTREQUEST_0_AMT='. $paymentAmount;
$nvpstr .= '&PAYMENTREQUEST_0_PAYMENTACTION='.$this->_paymentType;
$nvpstr .= '&RETURNURL='.$returnURL;
$nvpstr .= '&CANCELURL='.$cancelURL;
$nvpstr .= '&PAYMENTREQUEST_0_CURRENCYCODE='.$this->_currency;
$nvpstr .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
我所做的就是将最后一行添加到这段代码中


为了将来的参考,你可能有兴趣看看我的。它比您正在使用的这个要完整得多,而且使用起来非常简单。

嗨,安德鲁,我试着按照您的建议做了,但是当我进入paypal页面时,它仍然要求我创建一个paypal帐户。不会让我以访客身份付款。还需要确保在您的PayPal配置文件中启用了PayPal帐户可选选项。我认为这是在网站支付偏好下。将$ntpstr输出到屏幕,这样我们就可以看到生成的全部价值。需要再次检查它是否按照我们预期的方式生成。我一直使用快速结帐和客人结帐,这是唯一需要的步骤,所以我们一定错过了什么。非常感谢安德鲁!它正在工作,但在我登录paypal并单击“继续”后,它不会将我带到计算运费的页面。是否还有其他代码块需要添加?尝试呼叫paypal,但已关闭。登录并查看订单后,单击“继续”将返回SetExpressCheckout中指定的返回URL。在这里,您可以调用GetExpressCheckoutDetails获取付款人的发货地址,并根据该地址计算发货。在调用DoExpressCheckoutPayment之前,您可以显示包括装运/税务在内的最终审核。您也可以使用Instant Update API将配送选项发送到PayPal review页面,但这需要更多的时间,而且效果并不理想。