如何使用 Paypal Adeptive 获取 paykey 并在结帐时成功结帐?
Posted
技术标签:
【中文标题】如何使用 Paypal Adeptive 获取 paykey 并在结帐时成功结帐?【英文标题】:How to get paykey using Paypal Adeptive and make successful checkout in checkout? 【发布时间】:2014-05-08 11:22:23 【问题描述】:我正在使用使用灯箱的贝宝自适应并行支付,以便用户驻留在我自己的网站上而无需重定向。
我只是想当我点击付款按钮时,我会在表单中获得动态密钥,等等,张贴表单灯箱打开,我从发件人那里获得付款并将钱分成 2 个帐户。
paypal business account:
mohsin@balianti.com that is my site admin account as well. who will receive 10% from total amount.
sanbox account that i created in mohsin@balianti.com sandbox account options: mmskit@outlook.com that will receive 90% of total money.
so mohsin@balianti.com as a site admin and holding business account will receive 10% while other receiver will receive 90%.
means total money will split in both accounts.
希望你能明白我的意思。
问题是:
1- i am not getting paykey from paypal.
2- i am unable to do the transaction in light box.
3- i am unable to slipt the money in 2 receivers and so unable to complete to process.
我的 html 代码:
<html>
<head>
<script src="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>
</head>
<body>
<!--https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=AP-5S482348KH512131U-->
<form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=NOT KNOW HOW TO GET THIS PAY KEY ON THE BUTTON CLICK" target="PPDGFrame" class="standard">
<label for="buy">Buy Now:</label>
<input type="image" id="submitBtn" value="Pay with PayPal" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif">
</form>
<script type="text/javascript" charset="utf-8">
var embeddedPPFlow = new PAYPAL.apps.DGFlow(trigger: 'submitBtn');
</script>
</body>
</html>
我的 Config.php 文件:
<?php
/**
* Timezone Setting
* List of Supported Timezones: http://www.php.net/manual/en/timezones.php
*/
date_default_timezone_set('America/Chicago');
/**
* Enable Sessions
* Checks to see if a session_id exists. If not, a new session is started.
*/
if(!session_id()) session_start();
/**
* Sandbox Mode - TRUE/FALSE
* Check the domain of the current page and set $sandbox accordingly.
* This allows you to automatically use Sandbox or Live credentials throughout
* your application based on what server the app is running from.
*
* I like to do this so I don't forget to update Sandbox credentials to Live
* prior to uploading files to a production server.
*
* In this case, it's checking to see if the current URL is http://sandbox.domain.*
* If so, $sandbox is true and the PayPal sandbox will be used throughout. If not,
* we'll assume it must be a live transaction and will use live credentials throughout.
*
* Following this pattern will allow you to create your own http://sandbox.domain.com test server,
* and then any time your code runs from that server, PayPal's sandbox will be used automatically.
*
* If you would rather just set $sandbox to true/false on your own that's fine,
* but you have to make sure your live server always uses false and your test server
* always uses true. It's easy to forget this and up with real customers processing
* payments from your live site on the PayPal sandbox.
*/
$host_split = explode('.',$_SERVER['HTTP_HOST']);
$sandbox = $host_split[0] == 'sandbox' && $host_split[1] == 'domain' ? TRUE : FALSE;
$domain = $sandbox ? 'http://sandbox.domain.com/' : 'http://lahori.org/mydev/themusicnetwork/';
/**
* Enable error reporting if running in sandbox mode.
*/
if($sandbox)
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', '1');
/*
* PayPal API Version
* ------------------
* The library is currently using PayPal API version 109.0.
* You may adjust this value here and then pass it into the PayPal object when you create it within your scripts to override if necessary.
*/
$api_version = '109.0';
/*
* PayPal Application ID
* --------------------------------------
* The application is only required with Adaptive Payments applications.
* You obtain your application ID but submitting it for approval within your
* developer account at http://developer.paypal.com
*
* We're using shorthand if/else statements here to set both Sandbox and Production values.
* Your sandbox values go on the left and your live values go on the right.
* The sandbox value included here is a global value provided for developrs to use in the PayPal sandbox.
*/
$application_id = $sandbox ? 'APP-80W284485P519543T' : '';
/*
* PayPal Developer Account Email Address
* This is the email address that you use to sign in to http://developer.paypal.com
*/
$developer_account_email = 'mohsin@balianti.com';
/*
* PayPal Gateway API Credentials
* ------------------------------
* These are your PayPal API credentials for working with the PayPal gateway directly.
* These are used any time you're using the parent PayPal class within the library.
*
* We're using shorthand if/else statements here to set both Sandbox and Production values.
* Your sandbox values go on the left and your live values go on the right.
*
* You may obtain these credentials by logging into the following with your PayPal account: https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run
*/
$api_username = $sandbox ? 'mohsin_api1.balianti.com' : 'LIVE_API_USERNAME';
$api_password = $sandbox ? 'DAQQ3QK5LTHHWGYV' : 'LIVE_API_PASSWORD';
$api_signature = $sandbox ? 'Ad9JZLf8.13dlHmFgFft2NVbaPK4AvTXPIYEMvf.CyBXiGxnrmbQG4l2' : 'LIVE_API_SIGNATURE';
/*
* Payflow Gateway API Credentials
* ------------------------------
* These are the credentials you use for your PayPal Manager: http://manager.paypal.com
* These are used when you're working with the PayFlow child class.
*
* We're using shorthand if/else statements here to set both Sandbox and Production values.
* Your sandbox values go on the left and your live values go on the right.
*
* You may use the same credentials you use to login to your PayPal Manager,
* or you may create API specific credentials from within your PayPal Manager account.
*/
$payflow_username = $sandbox ? 'SANDBOX_PAYFLOW_USERNAME' : 'LIVE_PAYFLOW_USERNAME';
$payflow_password = $sandbox ? 'SANDBOX_PAYFLOW_PASSWORD' : 'LIVE_PAYFLOW_PASSWORD';
$payflow_vendor = $sandbox ? 'SANDBOX_PAYFLOW_VENDOR' : 'LIVE_PAYFLOW_VENDOR';
$payflow_partner = $sandbox ? 'SANDBOX_PAYFLOW_PARTNER' : 'LIVE_PAYFLOW_PARTNER';
/*
* PayPal REST API Credentials
* ---------------------------
* These are the API credentials used for the PayPal REST API.
* These are used any time you're working with the REST API child class.
*
* You may obtain these credentials from within your account at http://developer.paypal.com
*/
$rest_client_id = $sandbox ? 'AUjqAhB6ZWMudj58C_NAC0kA58EmNCl2LPFlmaX76t1e0kVu-GwALjzVTBwR' : 'LIVE_CLIENT_ID';
$rest_client_secret = $sandbox ? 'EPXlgBAIfaptG15JI7OxxZK1GNxgfAqQg5uhmllzdF1FIE5hjEhsIBbrwfbV' : 'LIVE_SECRET_ID';
/*
* PayPal Finance Portal API
* -------------------------
* These are credentials used for obtaining a PublisherID used in Bill Me Later Banner code.
* As of now, these are specialized API's and you must obtain credentials directly from a PayPal rep.
*/
$finance_access_key = $sandbox ? 'SANDBOX_ACCESS_KEY' : 'LIVE_ACCESS_KEY';
$finance_client_secret = $sandbox ? 'SANDBOX_CLIENT_SECRET' : 'LIVE_CLIENT_SECRET';
/**
* Third Party User Values
* These can be setup here or within each caller directly when setting up the PayPal object.
*/
$api_subject = ''; // If making calls on behalf a third party, their PayPal email address or account ID goes here.
$device_id = '';
$device_ip_address = $_SERVER['REMOTE_ADDR'];
?>
我的 PHP 代码来自 angel's eye paypal 课程:
<?php
// Include required library files.
require_once('config.php');
require_once('paypal.class.php');
require_once('paypal.adaptive.class.php');
// Create PayPal object.
$PayPalConfig = array(
'Sandbox' => $sandbox,
'DeveloperAccountEmail' => $developer_account_email,
'ApplicationID' => $application_id,
'DeviceID' => $device_id,
'IPAddress' => $_SERVER['REMOTE_ADDR'],
'APIUsername' => $api_username,
'APIPassword' => $api_password,
'APISignature' => $api_signature,
'APISubject' => $api_subject
);
$PayPal = new PayPal_Adaptive($PayPalConfig);
// Prepare request arrays
$PayRequestFields = array(
'ActionType' => 'PAY', // Required. Whether the request pays the receiver or whether the request is set up to create a payment request, but not fulfill the payment until the ExecutePayment is called. Values are: PAY, CREATE, PAY_PRIMARY
'CancelURL' => $domain.'cancel.php', // Required. The URL to which the sender's browser is redirected if the sender cancels the approval for the payment after logging in to paypal.com. 1024 char max.
'CurrencyCode' => 'USD', // Required. 3 character currency code.
'FeesPayer' => 'EACHRECEIVER', // The payer of the fees. Values are: SENDER, PRIMARYRECEIVER, EACHRECEIVER, SECONDARYONLY
'IPNNotificationURL' => '', // The URL to which you want all IPN messages for this payment to be sent. 1024 char max.
'Memo' => '', // A note associated with the payment (text, not HTML). 1000 char max
'Pin' => '', // The sener's personal id number, which was specified when the sender signed up for the preapproval
'PreapprovalKey' => '', // The key associated with a preapproval for this payment. The preapproval is required if this is a preapproved payment.
'ReturnURL' => $domain.'return.php', // Required. The URL to which the sener's browser is redirected after approvaing a payment on paypal.com. 1024 char max.
'ReverseAllParallelPaymentsOnError' => '', // Whether to reverse paralel payments if an error occurs with a payment. Values are: TRUE, FALSE
'SenderEmail' => '', // Sender's email address. 127 char max.
'TrackingID' => '' // Unique ID that you specify to track the payment. 127 char max.
);
$ClientDetailsFields = array(
'CustomerID' => '', // Your ID for the sender 127 char max.
'CustomerType' => '', // Your ID of the type of customer. 127 char max.
'GeoLocation' => '', // Sender's geographic location
'Model' => '', // A sub-identification of the application. 127 char max.
'PartnerName' => 'Always Give Back' // Your organization's name or ID
);
$FundingTypes = array('ECHECK', 'BALANCE', 'CREDITCARD');
$Receivers = array();
$Receiver = array(
'Amount' => '10.00', // Required. Amount to be paid to the receiver.
'Email' => 'mohsin@balianti.com', // Receiver's email address. 127 char max.
'InvoiceID' => '', // The invoice number for the payment. 127 char max.
'PaymentType' => 'GOODS', // Transaction type. Values are: GOODS, SERVICE, PERSONAL, CASHADVANCE, DIGITALGOODS
'PaymentSubType' => '', // The transaction subtype for the payment.
'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => ''), // Receiver's phone number. Numbers only.
'Primary' => 'TRUE' // Whether this receiver is the primary receiver. Values are boolean: TRUE, FALSE
);
array_push($Receivers,$Receiver);
$Receiver = array(
'Amount' => '5.00', // Required. Amount to be paid to the receiver.
'Email' => 'mmskit@outlook.com', // Receiver's email address. 127 char max.
'InvoiceID' => '', // The invoice number for the payment. 127 char max.
'PaymentType' => 'GOODS', // Transaction type. Values are: GOODS, SERVICE, PERSONAL, CASHADVANCE, DIGITALGOODS
'PaymentSubType' => '', // The transaction subtype for the payment.
'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => ''), // Receiver's phone number. Numbers only.
'Primary' => 'false' // Whether this receiver is the primary receiver. Values are boolean: TRUE, FALSE
);
array_push($Receivers,$Receiver);
$SenderIdentifierFields = array(
'UseCredentials' => '' // If TRUE, use credentials to identify the sender. Default is false.
);
$AccountIdentifierFields = array(
'Email' => '', // Sender's email address. 127 char max.
'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => '') // Sender's phone number. Numbers only.
);
$PayPalRequestData = array(
'PayRequestFields' => $PayRequestFields,
'ClientDetailsFields' => $ClientDetailsFields,
'FundingTypes' => $FundingTypes,
'Receivers' => $Receivers,
'SenderIdentifierFields' => $SenderIdentifierFields,
'AccountIdentifierFields' => $AccountIdentifierFields
);
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->Pay($PayPalRequestData);
if(!$this->paypal_adaptive->APICallSuccessful($PayPalResult['Ack']))
$errors = array('Errors'=>$PayPalResult['Errors']);
// Write the contents of the response array to the screen for demo purposes.
echo '<pre />';
print_r($errors);
exit();
else
header('Location: '.$PayPalResult['RedirectURL']);
$ExecutePaymentFields = array(
'PayKey' => $PayPalResult['PayKey'],
'FundingPlanID' => ''
);
$PayPalRequestData = array('ExecutePaymentFields' => $ExecutePaymentFields);
$PayPalResult = $PayPal->ExecutePayment($PayPalRequestData);
if(!$PayPalResult)
$errors = array('Errors'=>$PayPalResult['Errors']);
echo '<pre />';
print_r($errors);
exit();
else
echo '<pre />';
print_r($PayPalResult);
if($PayPal->APICallSuccessful($PayPalResult['Ack']))
// Redirect to PayPal so user can complete payment.
header('Location: '.$PayPalResult['RedirectURL']);
else
// Error
echo '<pre />';
print_r($PayPalResult['Errors']);
exit();
?>
我从贝宝收到的登录信息和完整的详细级别信息。
REST API 凭据
测试凭据
您的应用中的所有功能都启用了您的测试凭据。
Test account:
mohsin-facilitator@balianti.com
Endpoint: api.sandbox.paypal.com
Client ID: AUjqAhB6ZWMudj58C_NAC0kA58EmNCl2LPFlmaX76t1e0kVu-GwALjzVTBwR
Secret: EPXlgBAIfaptG15JI7OxxZK1GNxgfAqQg5uhmllzdF1FIE5hjEhsIBbrwfbV
这是您的 API 签名:
API Username: mohsin_api1.balianti.com
API Password: DAQQ3QK5LTHHWGYV
Signature: Ad9JZLf8.13dlHmFgFft2NVbaPK4AvTXPIYEMvf.CyBXiGxnrmbQG4l2
将上面的 PayPal 设置复制并粘贴到 Magento 配置页面的 API/集成部分。
您已成功保存您的首选项。在您的网站上设置支付数据传输时,请使用以下身份令牌。 A9XxF-vXyH3-kPYVX0dDDcojmBxvMidXnmn846gxQD0ehzXM4Xjva0VL6RW
http://developer.paypal.com
mohsin@balianti.com
m@h$!nBali
请帮我解决整个问题。我正在等待认真的答复。
谢谢大家。
【问题讨论】:
@Andrew K. Angell 请帮忙...... 您是否自己运行过 Pay.php 以确保您从 PayPal 收到 PayKey 的有效响应? 我已经尝试运行它自己的文件,但我没有得到贝宝的任何响应。 请看在上帝的份上,由于这个问题,我的截止日期已经晚了,请编辑我的代码并制作一些最能帮助我的工作代码。我正在使用你的图书馆。 请帮我解决这个问题,因为我对熟练的贝宝很陌生。 【参考方案1】:我获取了您的代码并在我的服务器上运行它。
我注意到的第一件事是,您在加载的 $PayPalResult 下方已将所有内容都注释掉了,因此该结果实际上并没有发生任何事情。没有输出到屏幕或返回到请求的客户端。
当我使用我的凭据运行它并查看实际结果时,这就是我得到的结果。
[Errors] => Array
(
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 520009
[ExceptionID] =>
[Message] => Account mohsin@balianti.com is restricted
[Parameter] => mohsin@balianti.com
[Severity] => Error
[Subdomain] => Application
)
)
[Ack] => Failure
[Build] => 10273932
[CorrelationID] => 471e9fbfa0053
[Timestamp] => 2014-03-29T09:45:56.631-07:00
因此,您在此使用的接收方帐户似乎有问题。当我进一步研究时,我发现您在同一笔付款中设置了相同的接收方作为主要和次要接收方。
一旦我用我自己的沙盒帐户中的 2 封单独的电子邮件替换了您的收件人电子邮件地址,我就得到了成功的回复。
[Ack] => Success
[Build] => 10273932
[CorrelationID] => 9afd1342ebf17
[Timestamp] => 2014-03-29T09:50:00.472-07:00
[PayKey] => AP-8FY50816521434738
[PaymentExecStatus] => CREATED
然后,我返回并尝试将您的帐户与我的一个帐户一起作为接收者,但我最终遇到了关于帐户被限制的相同错误。
所以,我不确定为什么该帐户会受到限制,尤其是在沙盒上。不过,它看起来不像沙盒电子邮件帐户。是一个吗?在沙盒上进行测试时,您需要确保您使用的是沙盒帐户。
如果您实际上是在访问实时服务器并遇到相同的错误,那么您需要contact PayPal 以获取有关该帐户问题的帮助。
但是,如果您正在实时运行,您可能会遇到不同的错误。要检查您是否需要查看返回到 $PayPalResult 的实际结果。同样,您已经在代码中注释掉了所有这些内容,因此它甚至不会将结果返回给您的客户端请求。
【讨论】:
尊敬的先生,我在我的沙盒帐户中创建了 2 个新帐户,但它们仍然在灯箱中给出相同的错误。 你能帮我写一个优化的代码吗?请那可以在灯箱中给我结果并将钱分配到 2 个接收器中,一个是站点管理员,一个是购物车管理员,另一个是另一个接收器。 我要编辑我的整个代码。请同时参考我的沙盒证书。我现在发布我的整个表格和证书。请先生为我优化代码。 我的 mohsin@balianti.com 是业务类型的沙盒帐户。所以它的商业账户。我想要的是拥有商业帐户的主站点管理员收到 10%,其他接收者收到 90%,并且资金同时进入两个帐户。我希望所有这些都在灯箱中,所以在灯箱中发送登录信息并通过付款,站点管理员获得 10%,其他接收者收到 90%。请以这种方式编辑我的整个代码。请。 亲爱的安德鲁先生,请再次阅读我的整个问题。非常感谢您的大力帮助。我现在已经和你分享了全部信息。请让我摆脱这个问题。我的客户现在真的在失去潜在客户。请。【参考方案2】:请看:
Array
(
[Errors] => Array
(
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 580022
[ExceptionID] =>
[Message] => Invalid request parameter: payKey cannot be null
[Parameter] => payKey
[Severity] => Error
[Subdomain] => Application
)
)
[Ack] => Failure
[Build] => 10273932
[CorrelationID] => 2d63bc22401c7
[Timestamp] => 2014-04-15T02:27:08.040-07:00
[PaymentExecStatus] =>
[XMLRequest] => ReturnAllen_US
[XMLResponse] => 2014-04-15T02:27:08.040-07:00Failure2d63bc22401c710273932580022PLATFORMApplicationErrorApplicationInvalid request parameter: payKey cannot be nullpayKeynull
)
odftetretArray
(
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 580022
[ExceptionID] =>
[Message] => Invalid request parameter: payKey cannot be null
[Parameter] => payKey
[Severity] => Error
[Subdomain] => Application
)
)
【讨论】:
凭据不会显示在此处,因为当您使用 Adaptive Payments 时,它们会在标头中发送,而不是在 API 请求中发送。您只需要仔细检查您的值以及您发布到正确的端点。 谢谢亲爱的先生。请让我检查一下。我正在使用您的课程,但不确定我在这里做错了什么。 Contact me directly 我可以为您提供更多帮助。 尊敬的先生,我已将电子邮件发送给您。 如果您向我询问所有文件,我可以与您分享我的所有文件,并在进一步请求时通过电子邮件附件发送给您。以上是关于如何使用 Paypal Adeptive 获取 paykey 并在结帐时成功结帐?的主要内容,如果未能解决你的问题,请参考以下文章
如何在 PayPal Manager 中获取 PayPal 缺少错误代码?
在 PayPal 付款后如何获取 TransactionID