Регулярная оплата Paypal Express Checkout

Когда я следил за существующим примером PayPal, я не могу получить информацию о заказе в экспресс-кассе PayPal, как я могу это сделать, я даю свое место, где я не получаю информацию о заказе, следующим образом:

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

$environment = 'sandbox';   // or 'beta-sandbox' or 'live'

/**
 * 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
 */
function PPHttpPost($methodName_, $nvpStr_) {
    global $environment;

    // Set up your API credentials, PayPal end point, and API version.
    $API_UserName = urlencode('super_secret_username');
    $API_Password = urlencode('super_secret_password');
    $API_Signature = urlencode('super_secret_signature');
    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {
        $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
    }
    $version = urlencode('51.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;
}

// Set request-specific fields.
$paymentAmount = urlencode('105.87');
$currencyID = urlencode('USD');                         // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
$paymentType = urlencode('Authorization');              // or 'Sale' or 'Order'

$returnURL = urlencode("http://localhost/paypal/new/success.php");
$cancelURL = urlencode('http://localhost/paypal/new/cencel.php');

// Add request-specific fields to the request string.
$nvpStr = "&Amt=$paymentAmount&ReturnUrl=$returnURL&CANCELURL=$cancelURL&PAYMENTACTION=$paymentType&CURRENCYCODE=$currencyID";


// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('SetExpressCheckout', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    // Redirect to paypal.com.
    $token = urldecode($httpParsedResponseAr["TOKEN"]);
    $payPalURL = "https://www.paypal.com/webscr&cmd=_express-checkout&token=$token";
    if("sandbox" === $environment || "beta-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));
}

используя этот скрипт, как мне получить общую сумму заказа.

Мне нужен скрипт для периодической оплаты Paypal с использованием Payal Express Checkout. Мне также нужно Обновить и отменить регулярный платеж.


person Md. Ruzdi Islam    schedule 09.03.2012    source источник
comment
Рузди Ислам, предоставленный вами код полностью зависит от предоставленных данных. По сути, вы не предоставили достаточно информации. function func (that) {do this [that];}. Это в основном то, что вы предоставили. Предоставьте список переменных, которые вы отправляете в PayPal, чтобы можно было исследовать ваш метод. Посмотрите на переменные L_PAYMENTREQUEST для экспресс-оплаты, так как вам нужно отправить позиции, чтобы их увидеть.   -  person SgtPooki    schedule 10.03.2012


Ответы (1)


Для успешной публикации вашего кода необходимо установить некоторые дополнительные параметры. Также я убрал некоторые дополнительные ошибки, которые вы обнаружите, если сравните два примера. Главное:

  1. $returnURL и $cancelURL должны быть реальным URL и без метода urlencode()

  2. $version должен быть установлен в urlencode('124.0');

  3. Параметры для SetExpressCheckout должны быть установлены, как в примере.

  4. Рекомендую протестировать вживую, просто выставьте цену в $0.01

    Следуйте примеру ниже:

 


/** SetExpressCheckout NVP example; last modified 08MAY23. * * Initiate an Express Checkout transaction. */ $environment = 'live'; // or 'beta-sandbox' or 'live'
/** * 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 */
function PPHttpPost($methodName_, $nvpStr_) {
global $environment;

// Set up your API credentials, PayPal end point, and API version.
$API_UserName = urlencode('super_secret_username');
$API_Password = urlencode('super_secret_password');
$API_Signature = urlencode('super_secret_signature');
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if("sandbox" === $environment || "beta-sandbox" === $environment) {
$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
}
$version = urlencode('124.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;
}
// Set request-specific fields. $paymentAmount = urlencode('105.87'); $currencyID = urlencode('USD'); // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD') $paymentType = urlencode('Authorization'); // or 'Sale' or 'Order'
$returnURL = "http://localhost/paypal/new/success.php"; // Please provide a real URL !!!!!
$cancelURL = 'http://localhost/paypal/new/cencel.php'; // Please provide a real URL !!!!!
//Parameters for SetExpressCheckout, which will be sent to PayPal
$paypal_data = array( 'RETURNURL' => $returnURL,
'CANCELURL' => $cancelURL,
'PAYMENTREQUEST_0_CURRENCYCODE' => $$currencyID,
'PAYMENTREQUEST_0_PAYMENTACTION'=> 'SALE',
'PAYMENTREQUEST_0_DESC' => 'Hosted Saas Tier 1 and Community Management Services',
'PAYMENTACTION' => $paymentType,
'L_BILLINGTYPE0' => 'RecurringPayments',
'L_BILLINGAGREEMENTDESCRIPTION0'=> 'Description of Community Management Services',
'L_PAYMENTREQUEST_0_NAME0' => 'Community Management Services 8 hours for $0.01',
'L_PAYMENTREQUEST_0_NUMBER0' => '010101',
'L_PAYMENTREQUEST_0_QTY0' => '1',
'L_PAYMENTREQUEST_0_AMT0' => $paymentAmount,

/** * If you want second recurring payment in the same session * 'L_BILLINGTYPE1' => 'RecurringPayments', * 'L_BILLINGAGREEMENTDESCRIPTION1'=> 'Description of Hosted Saas Tier 1', * 'L_PAYMENTREQUEST_0_NAME1' => 'Hosted Saas Tier 1', * 'L_PAYMENTREQUEST_0_NUMBER1' => '212121', * 'L_PAYMENTREQUEST_0_QTY1' => '1', * 'L_PAYMENTREQUEST_0_AMT1' => '0.02', */
'PAYMENTREQUEST_0_ITEMAMT' => $paymentAmount, 'PAYMENTREQUEST_0_AMT' => $paymentAmount ); $nvpStr = http_build_query($paypal_data);
// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('SetExpressCheckout', $nvpStr);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
// Redirect to paypal.com.
$token = urldecode($httpParsedResponseAr["TOKEN"]);
$payPalURL = "https://www.paypal.com/webscr&cmd=_express-checkout&token=$token";
if("sandbox" === $environment || "beta-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));
}
person Pavel Kenarov    schedule 17.09.2015