Codeigniter 沙箱贝宝金钱扣减问题 我的代码: function paiement_echec() { 回显“用户取消付款”; } 函数paiement_success() { //从贝宝获得代币。 如果(!array\u key\u存在('token',$\u请求))

Codeigniter 沙箱贝宝金钱扣减问题 我的代码: function paiement_echec() { 回显“用户取消付款”; } 函数paiement_success() { //从贝宝获得代币。 如果(!array\u key\u存在('token',$\u请求)),codeigniter,paypal,Codeigniter,Paypal,沙箱贝宝金钱扣减问题 我的代码: function paiement_echec() { 回显“用户取消付款”; } 函数paiement_success() { //从贝宝获得代币。 如果(!array\u key\u存在('token',$\u请求)) 退出('未收到令牌'); //设置特定于请求的字段。 $token=urlencode(htmlspecialchars($_请求['token']); //将特定于请求的字段添加到请求字符串。 $nvpStr=“&TOKEN=$TOKEN”

沙箱贝宝金钱扣减问题 我的代码:
function paiement_echec()
{
回显“用户取消付款”;
}
函数paiement_success()
{
//从贝宝获得代币。
如果(!array\u key\u存在('token',$\u请求))
退出('未收到令牌');
//设置特定于请求的字段。
$token=urlencode(htmlspecialchars($_请求['token']);
//将特定于请求的字段添加到请求字符串。
$nvpStr=“&TOKEN=$TOKEN”;
//执行API操作;请参阅上面的PPHttpPost函数。
$httpParsedResponseAr=$this->PPHttpPost('GetExpressCheckoutDetails',$nvpStr);
if(“SUCCESS”==strotupper($httpParsedResponseAr[“ACK”])| |“SUCCESSWITHWARNING”==strotupper($httpParsedResponseAr[“ACK”]))
{
//打印(httpParsedResponseAr);
$payerID=urlencode($httpParsedResponseAr[“payerID”]);
//$token=urlencode(“token”);
$paymentType=urlencode('Sale');//或'Sale'或'Order'
$paymentAmount=urlencode(“4.39”);
$currencyID=urlencode(“USD”);//或其他货币代码(“英镑”、“欧元”、“日元”、“加元”、“澳元”)
//将特定于请求的字段添加到请求字符串。
$nvpStr=“&TOKEN=$TOKEN&PAYERID=$PAYERID&PAYMENTACTION=$paymentType&AMT=$paymentAmount&CURRENCYCODE=$currencyID”;
$httpParsedResponseAr=$this->PPHttpPost('DoExpressCheckoutPayment',$nvpStr);
if(“SUCCESS”==strotupper($httpParsedResponseAr[“ACK”])| |“SUCCESSWITHWARNING”==strotupper($httpParsedResponseAr[“ACK”]))
{
$this->load->model('payment_model');
$this->payment_model->paypal_payment();
$msg=“谢谢!!您的付款已成功完成
";
echo$msg;
}
其他的
{
退出('GetExpressCheckoutDetails失败:'。打印($httpParsedResponseAr,true));
//echo“由于未知原因支付失败”;
}
} 
其他的
{
//退出('GetExpressCheckoutDetails失败:'。打印($httpParsedResponseAr,true));
echo“由于未知原因支付失败”;
}
}
函数pay_by_paypal()
{
$environment='sandbox';
$\u会话['item\u name']=$this->input->post('item\u name');
$\会话['amount']=$this->input->post('amount');
$\会话['currency\u code']=$this->input->post('currency\u code');
$\会话['no\ u of\ u photo']=$this->input->post('no\ u of\ u photo');
$qty=urlencode(“1”);
$product_name=urldecode($_会话['item_name']);
$price=urlencode($_会话['amount']);
//$currencyID=urlencode($会话['currency\u code']);
$currencyID=urlencode(“美元”);
//或其他货币代码(“英镑”、“欧元”、“日元”、“加元”、“澳元”)
$paymentType=urlencode('Order');
$nvpStr=“”;
$returnURL=(base_url()“paient/paient_success”);
$cancelURL=(base_url()“paiement/paiement_echec”);
$i=0;
$total_amount=0;
$str=“&METHOD=SetExpressCheckout
&RETURNURL=$RETURNURL
&CANCELURL=$CANCELURL
&L_PAYMENTREQUEST_0_NAME0=$product_name
&L_PAYMENTREQUEST_0_NUMBER0=$qty
&L_PAYMENTREQUEST_0_AMT0=美元价格
&L_PAYMENTREQUEST_0_DESC0=$product_name
&PAYMENTREQUEST\u 0\u金额=$price
&PAYMENTREQUEST\u 0\u PAYMENTACTION=$paymentType
&PAYMENTREQUEST\u 0\u CURRENCYCODE=$currencyID”;
$nvpStr=$nvpStr.$str;
$httpParsedResponseAr=$this->PPHttpPost('SetExpressCheckout',$nvpStr);
if(“SUCCESS”==strotupper($httpParsedResponseAr[“ACK”])| |“SUCCESSWITHWARNING”==strotupper($httpParsedResponseAr[“ACK”]))
{
//重定向到paypal.com。
$token=urldecode($httpParsedResponseAr[“token”]);
$payPalURL=”https://www.$environment.paypal.com/webscr&cmd=\u express-checkout&token=$token”;
如果(“沙盒”==$environment)
{
$payPalURL=”https://www.$environment.paypal.com/webscr&cmd=\u express-checkout&token=$token”;
}
标题(“位置:$payPalURL”);
出口
} 
其他的
{
退出('SetExpressCheckout失败:'。打印($httpParsedResponseAr,true));
}
}
/**SetExpressCheckout NVP示例;最后修改日期为5月23日08时。
*
*启动快速结帐交易。
*/
/**
*发送HTTP POST请求
*
*@param string API方法名称
*@param string以&name=value对格式显示POST消息字段
*@return数组已解析HTTP响应正文
*/
私有函数PPHttpPost($methodName,$nvpStr){
//全球环境;
$environment='sandbox';//或'beta sandbox'或'live'
//设置API凭据、PayPal端点和API版本。
$API_UserName=urlencode('saswat_1360720799_biz_api1.gmail.com');
$API_Password=urlencode('1360720821');
$API_Signature=urlencode('ApDCeFez-N1Gd1-O3ubTGdpyiow4AlNlRemm8XJFcbsA.wbsmtllmsqhf');
$API_端点=”https://api-3t.paypal.com/nvp";
如果(“沙盒”==$environment){
$API_端点=”https://api-3t.$environment.paypal.com/nvp”;
}
$version=urlencode('65.0');
//设置旋度参数。
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$API_Endpoint);
curl_setopt($ch,CURLOPT_VERBOSE,1);
//关闭服务器和对等验证(TrustManager概念)。
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
卷曲设置($ch,卷曲设置桩,1);
//在请求中设置API操作、版本和API签名。
$nvpreq=“METHOD=$methodName&VERSION=$VERSION&PWD=$API\u Password&USER=$API\u UserName&SIGNATURE=$API\u SIGNATURE$nvpStr”;
//将请求设置为curl的POST字段。
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
//从服务器获取响应。
$httpResponse=curl\u exec($ch);
如果(!$httpResponse){
退出($methodName_uu失败:“.curl_错误($ch)。”(“.curl_错误($ch)。”);
}
//提取响应细节。
$httpResponseA
function paiement_echec()
    {
    echo "payment cancelled by the user";
    }

function paiement_succes()
{
  // Obtain the token from PayPal.
  if(!array_key_exists('token', $_REQUEST)) 
         exit('Token is not received.');
  // Set request-specific fields.
  $token = urlencode(htmlspecialchars($_REQUEST['token']));
  // Add request-specific fields to the request string.
  $nvpStr = "&TOKEN=$token";
  // Execute the API operation; see the PPHttpPost function above.
  $httpParsedResponseAr = $this->PPHttpPost('GetExpressCheckoutDetails', $nvpStr);
  if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) 
      {
          //print_r($httpParsedResponseAr);
          $payerID = urlencode($httpParsedResponseAr["PAYERID"]);
          //$token = urlencode("token");
          $paymentType = urlencode('Sale');         // or 'Sale' or 'Order'
          $paymentAmount = urlencode("4.39");
          $currencyID = urlencode("USD");                       // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
 
// Add request-specific fields to the request string.
          $nvpStr = "&TOKEN=$token&PAYERID=$payerID&PAYMENTACTION=$paymentType&AMT=$paymentAmount&CURRENCYCODE=$currencyID";
          $httpParsedResponseAr = $this->PPHttpPost('DoExpressCheckoutPayment', $nvpStr);
           if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) 
           {
             $this->load->model('payment_model');
             $this->payment_model->paypal_payment();
             $msg = "<label>Thank you !! your payment is successfully done</label>
              <a href='".base_url()."envoie_de_photos/envoyer_vos_photos"."'>Go To Photo Uploading</a>";
             echo $msg;
           }
          else  
            {
                 exit('GetExpressCheckoutDetails failed: ' . print_r($httpParsedResponseAr, true));
             //echo "Payment failed for unknown reason";
            }
      } 
  else  
      {
        //exit('GetExpressCheckoutDetails failed: ' . print_r($httpParsedResponseAr, true));
        echo "Payment failed for unknown reason";
      }
}


function pay_by_paypal()
{
  
        $environment = 'sandbox';
        $_SESSION['item_name']=$this->input->post('item_name');
        $_SESSION['amount']=$this->input->post('amount');
        $_SESSION['currency_code']=$this->input->post('currency_code');
        $_SESSION['no_of_photo']=$this->input->post('no_of_photo');
        
        $qty=urlencode("1");
        $product_name=urldecode($_SESSION['item_name']);
        $price=urlencode($_SESSION['amount']);
        //$currencyID = urlencode($_SESSION['currency_code']);
        $currencyID = urlencode("USD");

        
  
// or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
     $paymentType = urlencode('Order'); 
     $nvpStr=""; 
     $returnURL = (base_url()."paiement/paiement_succes");
     $cancelURL = (base_url()."paiement/paiement_echec");  
     $i=0;
     $total_amount=0;
     
     $str = "&METHOD=SetExpressCheckout
&RETURNURL=$returnURL
&CANCELURL=$cancelURL
&L_PAYMENTREQUEST_0_NAME0=$product_name
&L_PAYMENTREQUEST_0_NUMBER0=$qty
&L_PAYMENTREQUEST_0_AMT0=$price
&L_PAYMENTREQUEST_0_DESC0=$product_name
&PAYMENTREQUEST_0_AMT=$price
&PAYMENTREQUEST_0_PAYMENTACTION=$paymentType
&PAYMENTREQUEST_0_CURRENCYCODE=$currencyID"; 
     $nvpStr=$nvpStr.$str;
$httpParsedResponseAr = $this->PPHttpPost('SetExpressCheckout', $nvpStr);
     
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
    {
    // Redirect to paypal.com.
    $token = urldecode($httpParsedResponseAr["TOKEN"]);
    $payPalURL = "https://www.$environment.paypal.com/webscr&cmd=_express-checkout&token=$token";
    if("sandbox" === $environment) 
            {
        $payPalURL = "https://www.$environment.paypal.com/webscr&cmd=_express-checkout&token=$token";
    }
    header("Location: $payPalURL");
    exit;
} 
else  
    {
    exit('SetExpressCheckout failed: ' . print_r($httpParsedResponseAr, true));
}
  
}

/** SetExpressCheckout NVP example; last modified 08MAY23.
 *
 *  Initiate an Express Checkout transaction. 
*/


/**
 * Send HTTP POST Request
 *
 * @param   string  The API method name
 * @param   string  The POST Message fields in &name=value pair format
 * @return  array   Parsed HTTP Response body
 */
private function PPHttpPost($methodName_, $nvpStr_) {
    //global $environment;
        $environment = 'sandbox';   // or 'beta-sandbox' or 'live'
    // Set up your API credentials, PayPal end point, and API version.
    $API_UserName = urlencode('saswat_1360720799_biz_api1.gmail.com');
    $API_Password = urlencode('1360720821');
    $API_Signature = urlencode('ApDCeFez-N1Gd1-O3ubTGdpyiow4AlNlRemm8XJFcbsA.WbSMtlMSqHf');
    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    if("sandbox" === $environment) {
        $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
    }
    $version = urlencode('65.0');

    // Set the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

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

    // Set the API operation, version, and API signature in the request.
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

    // Set the request as a POST FIELD for curl.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    // Get response from the server.
    $httpResponse = curl_exec($ch);

    if(!$httpResponse) {
        exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
    }

    // Extract the response details.
    $httpResponseAr = explode("&", $httpResponse);

    $httpParsedResponseAr = array();
    foreach ($httpResponseAr as $i => $value) {
        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {
            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
        }
    }

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
    }

    return $httpParsedResponseAr;
}