2

提交表单后,我必须使用 dodirect 付款方式。该表格将在网站上显示所有卡的详细信息,例如卡类型(visa 或 master)、卡卡号、安全号码、到期日期、卡上的姓名、地址、州、邮政、国家、电话、电子邮件等。

我搜索了如何使用dodirect方法,发现如下

<?php

/** DoDirectPayment NVP example; last modified 08MAY23.
 *
 *  Process a credit card payment. 
*/

$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('my_api_username');
    $API_Password = urlencode('my_api_password');
    $API_Signature = urlencode('my_api_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.
$paymentType = urlencode('Authorization');              // or 'Sale'
$firstName = urlencode('customer_first_name');
$lastName = urlencode('customer_last_name');
$creditCardType = urlencode('customer_credit_card_type');
$creditCardNumber = urlencode('customer_credit_card_number');
$expDateMonth = 'cc_expiration_month';
// Month must be padded with leading zero
$padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));

$expDateYear = urlencode('cc_expiration_year');
$cvv2Number = urlencode('cc_cvv2_number');
$address1 = urlencode('customer_address1');
$address2 = urlencode('customer_address2');
$city = urlencode('customer_city');
$state = urlencode('customer_state');
$zip = urlencode('customer_zip');
$country = urlencode('customer_country');               // US or other valid country code
$amount = urlencode('example_payment_amuont');
$currencyID = urlencode('USD');                         // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// Add request-specific fields to the request string.
$nvpStr =   "&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber".
            "&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName".
            "&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID";

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

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    exit('Direct Payment Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else  {
    exit('DoDirectPayment failed: ' . print_r($httpParsedResponseAr, true));
}

?>

我不知道如何在提交我网站上的表单时使用此代码。任何人都可以在提交表单后帮助我如何使用它。

提前致谢 :)

4

2 回答 2

2

这真的不是一个很好的构建功能。它基本上是希望您只填写函数中的值而不是传递它们。这是一个非常粗略的示例,您可以根据评论看到它最后一次更新是在 2008 年。

但是,如果您想使用它,您可以简单地填写所有那些显示诸如“my_api_username”之类的内容的占位符,其中包含您要实际包含的数据。

如果您想要更容易使用的东西,我建议使用我开发并维护多年的这个PHP PayPal 库。它是最新的并且包含用于运行 DoDirectPayment 的直接示例。您可以在几分钟内启动并运行它。

如果您对此感兴趣,我也会通过屏幕共享提供 30 分钟的免费培训。

于 2013-01-05T08:00:03.810 回答
1

实际上,在https://www.x.com/developers/paypal/documentation-tools/paypal-sdk-index#expresscheckoutnew上,作为官方 SDK 的一部分,有可用于 DoDirectPayment 的示例

建议使用官方 SDK 并查看其中的示例。如有任何问题,请在此处回复或在https://github.com/paypal/merchant-sdk-php/issues打开问题

于 2013-01-07T04:56:07.067 回答