【发布时间】:2013-08-14 09:39:34
【问题描述】:
以下代码基于Webform PayPal Integration in Drupal 7的示例
$paypal = array();
$paypal['cmd'] = '_xclick';
$paypal['business'] = variable_get('event_reg_paypal_address');
$paypal['receiver_email'] = $paypal['business'];
$paypal['page_style'] = 'huang_checkout';
$paypal['amount'] = variable_get('event_reg_paypal_cost');
$paypal['currency_code'] = 'GBP';
$paypal['item_name'] = 'Test Event Registration';
$paypal['tax'] = 0;
$paypal['custom'] = $submission->sid;
$paypal['return'] = $base_url.'/test/thanks';
$paypal['notify_url'] = $base_url.'/test/thanks';
$paypal['cancel_return'] = $base_url;
$paypal['first_name'] = //first name from submission
$paypal['country'] = 'UK';
$query = http_build_query($paypal, '', '&');
$url = $paypal_host . $query;
drupal_goto($url);
它是自定义模块代码的一部分并实现hook_webform_submission_insert()。提交表单时,$url 变量是从 $paypal 数组构建的,然后用户的浏览器重定向到,例如,
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=pete27_11_94-facilitator%40hotmail.com&receiver_email=pete27_11_94-facilitator%40hotmail.com&page_style=huang_checkout&amount=0.01&currency_code=GBP&item_name=Test+Event+Registration&tax=0&custom=24&return=http%3A%2F%2Fwww.pitmart.com%2Fformulak%2Ftest%2Fthanks&notify_url=http%3A%2F%2Fwww.pitmart.com%2Fformulak%2Ftest%2Fthanks&cancel_return=http%3A%2F%2Fwww.pitmart.com%2Fformulak&first_name=sdfgsdfg&country=UK
在我的贝宝开发者帐户中,有一个用户的电子邮件地址与 url 中一样,类型为 business-pro,但每次我提交时都会收到错误消息
We cannot process this transaction because there is a problem with the PayPal email address supplied by the seller. Please contact the seller to resolve the problem. If this payment is for an eBay listing, you can contact the seller via the "Ask Seller a Question" link on the listing page. When you have the correct email address, payment can be made at www.paypal.com.
我正在实时服务器上进行测试,而不是在本地无法访问。
我希望被带到一个贝宝登录表单,但只是得到了错误。
是否可以以这种方式将数据传递给贝宝? (直接在网址中,而不是通过表单“发布”)
我是否遗漏了一些会导致此故障的变量/数据?是否有文档列出了此类贝宝请求的最低配置?
编辑 - 缺少currency_code。因为添加了它,但仍然收到错误。
【问题讨论】:
-
对
drupal_goto()函数的进一步调查使我注意到可以在不使用http_build_query()的情况下生成查询字符串。使用这种新方法将我带到表单。不确定我是否理解其中的区别,但它似乎有效......