forms - 如何在提交表单时使用 dodirect payment paypal?

标签 forms payment-gateway paypal submission

提交表单后我必须使用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));
}

?>

我不知道如何在提交我网站上的表单时使用此代码。谁能帮我在提交表格后如何使用它。

提前致谢:)

最佳答案

这确实不是一个构建得非常好的函数。它基本上是希望您只在函数中填写值,而不是将它们传入。这是一个非常粗略的示例,您可以根据注释看到它的最后更新时间是 2008 年。

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

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

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

关于forms - 如何在提交表单时使用 dodirect payment paypal?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14156299/

相关文章:

android - PayFort Mobile SDK存卡

flutter - 如何在 Flutter 中使用 Razorpay Orders API?

wordpress - PayPal 的 WooCommerce 运费问题

rest - Payout (REST api) 功能是否旨在取代 Mass Pay(经典商家 api)?

Jquery:仅获取提交表单的输入

javascript - 将文本区域的值添加到已填充的输入中

javascript - 即使表单验证失败也会调用语义 UI onSuccess 回调

c# - 如何更改组合框控件中的下拉按钮?

paypal - 无法连接到主机输入服务器 Uri = https ://pilot-payflowpro. paypal.com:443

paypal - 是什么导致我的 PayPal IPN 脚本失败?