-2

我的代码:

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;
}

我在 Paypal 沙盒中有三个帐户:两个企业帐户和一个个人帐户。我所有的 Paypal 账户都将美元作为默认货币。

在上面的代码中,我使用欧元作为货币。

当我进行交易时,如果我从我的个人(买家)账户以欧元付款,那么我的买家账户将被扣除(从我的买家账户中扣除等量的美元)。这完全没问题,没有问题。

问题是没有任何金额被添加到我的企业或(卖家)账户中。

我在 Stack Overflow 上找到了一篇文章,内容如下:

如果交易的货币代码和卖家账户不匹配,那么钱不会被添加到卖家账户

我把欧元换成了美元,(因为我的沙盒卖家测试账户是美元),发现在把它换成美元之后,我的钱就会被添加到我的卖家账户中。

这只是沙盒的问题,还是也适用于实时贝宝?

我有一个网站,买家可以用 GBP、EUR、MYN、SGD、AUD 支付。

如果交易需要以特定的货币进行,即根据卖家账户设置的货币,则无需使用不同的货币。

由于在 SetExpressCheckOut 中传递的 currencyCode 应该与 DoExpressCheckout 匹配,并且由于我遇到的问题,currencyCode 需要与沙盒卖家帐户的相同,所以即使买家选择 GBP,我也必须将其发送到 SetExpressCheckout 作为卖家账户的货币代码。

4

2 回答 2

3

您应该通过相关企业帐户的控制面板添加您希望接收付款的货币。

转到Profile-> My Settings-> 财务信息选项卡和Currency Balances。从那里选择一种货币并将其添加到列表中。然后,您收到的付款将保存在相应的货币余额中,直到您将它们转换为您想要的任何东西。

于 2013-02-13T11:50:57.167 回答
1

默认情况下,以您不持有的货币进行的交易将被保留,直到您决定如何处理它们。如果您登录有问题的卖家账户,您应该会在您的历史记录下看到该交易。您应该能够从那里接受或拒绝它。

有两种方法可以解决这个问题:

  • 正如 Alderis 所说,将欧元作为货币余额添加到您的卖家账户中。
  • 让所有以您不持有的货币进行的交易自动被接受并转换为美元。为此,请登录卖家账户,点击Profile,然后点击Payment Receiving Preferences(在Selling preferences列中),然后将Block payments sent to me in a currency I didn't hold设置为No, accept them and convert them转换为美元,然后单击保存
于 2013-02-13T15:39:22.293 回答