gpt4 book ai didi

php - 在自定义托管结帐页面上保护/验证 Paypal Payments Pro 数据并将自定义数据提交给 PayPal

转载 作者:太空宇宙 更新时间:2023-11-03 16:28:10 24 4
gpt4 key购买 nike

我目前(第一次)使用 Paypal Payments Pro。我有一个注册的企业帐户、API 用户名、密码和签名。我还有一个(几乎)完整的结帐表格。但我有几个问题。该网站用于政治捐款,这意味着我需要收集其他信息,例如雇主和职位。我想将此信息发送并存储在 PayPal 的服务器上,但我不太确定该怎么做,所以我开始做一些研究。我现在有一个我认为可行的基本 paypal php 表单:

<?php

/** DoDirectPayment NVP example;
*
* Process a credit card payment.
*/

$environment = 'sandbox'; // '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 Username'); // set your api username
$API_Password = urlencode('My Password'); // set your api password
$API_Signature = urlencode('My Signature'); // set your api Signature

$API_Endpoint = "https://api.sandbox.paypal.com";
if("sandbox" === $environment || "beta-sandbox" === $environment) {
$API_Endpoint = "https://api.$environment.paypal.com";
}
$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('Sale'); // 'Authorization' or 'Sale'
$firstName = urlencode($_POST['firstName']);
$lastName = urlencode($_POST['lastName']);
$creditCardType = urlencode($_POST['card_type']);
$creditCardNumber = urlencode($_POST['card_number']);
$expDateMonth = $_POST['11'];
// Month must be padded with leading zero
$padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));

$expDateYear = urlencode($_POST['18']);
$cvv2Number = urlencode($_POST['cvv']);
$address1 = urlencode($_POST['address1']);
$address2 = urlencode($_POST['address2']);
$city = urlencode($_POST['customer_city']);
$state = urlencode($_POST['customer_state']);
$zip = urlencode($_POST['zip']);
$country = urlencode($_POST['state']); // US or other valid country code
$amount = urlencode($_POST['50']);
$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));
}

?>

我在网上找到了这个示例,这是我能够运行的第一个示例。问题是我不完全确定我可以在哪里存储额外的信息以发送到 Paypal 。另一个问题是,在 PayPal 网站上,它说永远不要使用 POST 发送实时交易,因为它不安全。那我应该用什么?我有 SSL,内容应该被加密。此外,如何防止用户直接导航到此页面并获取我的凭据?我看到有人建议将 php 文件放在 webroot 之外,这对我有用吗?

我知道我需要将有效性检查添加到实际的 php 文件中,一旦我获得基本的支付功能,我就可以添加它。

我遇到的另一个问题是将这些额外信息传递到 paypal 快速结帐页面。有可能这样做吗?我很确定我在这里看到了一篇关于那个的帖子,但我似乎再也找不到了。

简而言之:

如何安全地将数据传输到 PayPal?

如何将额外数据(雇主、职位等)传输到 PayPal?

如何确保我的 API 信息安全?

如果用户选择使用 PayPal Express,我如何发送额外数据?

如果可以随时获得这些信息,我感到非常抱歉,我真的已经尽我所能进行了尽可能多的研究: PayPal Research看来我现在有点不知所措,我真的很感激我能得到的任何帮助。链接到文档,解释某些事情应该如何工作。真的,我们将不胜感激。

感谢 StackOverflow!

最佳答案

恕我直言,我鼓励您对您的方法做出两项重大改变。

首先,我建议使用 PayPal 的 SDK 之一,而不是使用 curl 自己编写从 URL 向上的所有内容。当你不需要的时候,你正在对自己施加压力。参见例如https://github.com/paypal/codesamples-php/blob/master/Merchant/sample/code/DoDirectPayment.php

其次,PayPal 不是您的数据库;您需要自己的一个来存储您的额外信息(例如雇主和职位)。您可以做一些笨拙的事情来将您的一些数据推送到 PayPal 交易的传递字段中,但是您可能会遇到问题并且对这种方法不满意。公认的解决方案是生成您自己的交易记录(称之为捐赠或发票等)并将其存储在您的数据库中,并将此记录的唯一标识符作为 PayPal“invoice_id”从您的数据库传递给 PayPal。这还有一个额外的好处,即 PayPal 能够发现您这边的潜在错误,这些错误可能导致对同一笔交易向某人重复收费两次。

至于您的具体问题:

How do I securely transmit data to PayPal?

使用 https(你这样做)。最好通过 SDK,这有助于防止各种其他方式泄露信息,如果您自己编写代码,可能会无意中泄露信息。

How do I transmit extra data (Employer, Job Title, etc.) to PayPal?

不要;见上文。

How do I keep my API information secure?

仅将其保存在您的服务器上(发送至 PayPal 时除外),并妥善保护您的服务器。使用 https 来保护您的服务器和 PayPal 之间的通信(PayPal 无论如何都会强制执行)。

How can I send extra data if the user chooses to use PayPal express?

Express Checkout 和 DoDirectPayment 都支持发票字段。

关于php - 在自定义托管结帐页面上保护/验证 Paypal Payments Pro 数据并将自定义数据提交给 PayPal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29057846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com