如何制作SagePay BuyNow按钮? [英] How Do I Make a SagePay BuyNow Button?

查看:147
本文介绍了如何制作SagePay BuyNow按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PayPal,我可以轻松创建一个BuyNow按钮,其中包含我的商家信息,价格,税金,运费等。在SagePay中可以吗?

With PayPal, I can create a BuyNow button pretty easily, containing my merchant info, price, tax, shipping, etc. Is this possible in SagePay?

推荐答案

与PayPal的BuyNow按钮+ PDT流程相似的地方,所需的系统称为SagePay Form。首先,您需要创建一个这样的表单:

The desired system is called SagePay Form as far as similarity to PayPal's BuyNow button + PDT process. First, you need to create a FORM like so:

<form action="https://live.sagepay.com/gateway/service/vspform-register.vsp" method="POST" id="SagePayForm" name="SagePayForm">
    <input type="hidden" name="VPSProtocol" value="2.23" />
    <input type="hidden" name="TxType" value="PAYMENT" />
    <input type="hidden" name="Vendor" value="<?= $YOUR_VENDOR_LOGIN_NAME ?>" />
    <input type="hidden" name="Crypt" value="<?= $PAYMENT_CRYPT ?>">    
    <input type="image" src="images/buynow-sagepay.png" />
</form>

(一个人可以在此处将实时网址与测试网址交换: https://test.sagepay.com/gateway/service/vspform-register.vsp

(One can swap the live URL with a test one here: https://test.sagepay.com/gateway/service/vspform-register.vsp)

对于$ PAYMENT_CRYPT,您必须首先创建一个像这样的字符串:

As for the $PAYMENT_CRYPT, you have to first create a string like so:

VendorTxCode=406227821909
&Amount=32.00
&Currency=USD
&Description=1 ACME Widget
&SuccessURL=http://example.com/success.php
&FailureURL=http://example.com/fail.php
&BillingSurname=Smith
&BillingFirstnames=John
&BillingAddress1=123 Main Street
&BillingCity=Anywhere
&BillingPostCode=29555
&BillingCountry=USA
&DeliverySurname=Smith
&DeliveryFirstnames=John
&DeliverAddress1=123 Main Street
&DeliveryCity=Anywhere
&DeliveryPostCode=29555
&DeliveryCountry=USA

为什么在PayPal不需要的时候他们需要一些此类信息是愚蠢的,但是很好。文档清楚地指出,如果他们没有收到合法值(例如可以验证该城市和国家/地区的真实邮政编码)的合法值,并且会用于问题争议仲裁,那么事情就会出错。

It's kind of dumb why they need some of this information when PayPal doesn't, but oh well. The docs clearly say that the thing will error out if they don't receive legitimate values like a real postal code that validates for that city and country, and is also used for problem dispute arbitration.

在我的示例中,没有PP一样的税收或运输突破,因此您需要在显示此BuyNow按钮之前或必要时显示该信息确认页面或您发送的确认电子邮件。它们的确有一个& Basket =参数,可以在其中指定税金,但这与您自己可以在表单页面上显示的内容无关,并且不必要。因此,& Amount值必须是总值,而不是净值。也没有数量值(可以使用& Basket参数指定)。 & Basket参数很可能比结帐过程中已经可以在自己的表单上显示的参数多余。因此,这就是为什么我的示例未包含该示例的原因。

Note in my example that there's no tax or shipping breakout as PP has, so you'll need to display that as necessary before showing this BuyNow buton, or perhaps on your confirmation page or confirmation email you send. They do have a "&Basket=" parameter where the tax can be specified, but it's redundant to what you can display on your form page yourself and not necessary. Therefore, the &Amount value must be the gross value, not net. There is also no quantity value (which the &Basket parameter could be used to specify). More than likely you'll find the &Basket parameter just redundant to what you can already display on your own form during the checkout process. So, that's why my example didn't include it.

对于VendorTxCode来说,这是您创建的,以便您可以将订单追溯到适当的客户。

As for the VendorTxCode, that's something you create so that you can track the order back to the appropriate customer.

然后使用SagePay提供的加密密码,使用XOR + Base64编码对$ PAYMENT_CRYPT进行加密。它们具有AES + Binhex加密选项,但是这太过分了,您的服务器必须启用mcrypt库。某些共享托管计划 STILL 尚未启用!

This $PAYMENT_CRYPT is then encrypted using XOR + Base64 encoding, using the encryption password provided by SagePay. They have an AES + Binhex encryption option, but it's overkill and your server has to have the mcrypt library enabled. Some shared hosting plans STILL don't have the enabled yet!

它们提供了XOR示例,但这是您无数次看到的典型示例在计算机科学课程中,您反复遍历密码的每个ASCII码和数据的每个ASCII码,并取另一个的补码(XOR处理)。完成后,通过Base64编码提供安全的POST传输。 Base64编码使用PHP的内置函数。

They provide an XOR example, but it's the typical one you see countless times in Computer Science courses where you repeatedly loop through each ASCII code of the password and each ASCII code of the data and take the complement bit of the other (the XOR process). Once done, feed it through Base64 encoding for safe POST transfer. The Base64 encoding uses the built-in function from PHP.

此响应比PayPal的IPN流程更像PayPal的PDT流程。他们确实将某人引导到success.php和fail.php以及通过GET进行加密的URL响应,您可以将其解密和解析(base64解码+ XOR),但是困难在于客户可以在等待页面跳转之前关闭表单。重定向。在这种情况下,人们会在SagePay的控制面板中看到此信息,并且必须手动为客户完成交易。

The response from this is more like PayPal's PDT process than PayPal's IPN process. They do direct someone to success.php and fail.php along with an encrypted URL response via GET that you can unencrypt and parse (base64 decode + XOR), but the difficulty is that the customer can close the form before waiting for the page to redirect. In that case, one will see this in their control panel in SagePay and have to fulfill the transaction manually for the customer.

在success.php和fail.php上,由您决定。一旦查询字符串& crypt参数未加密,您就可以通过查看Status参数为 OK来解析交易是否完成。

On the success.php and fail.php it's up to you what you want to do. Once the query string &crypt parameter is unencrypted, you'll be able to parse out whether the transaction is complete or not by looking at Status parameter being "OK".

请注意,您不必直接访问success.php。您可以使其像success.php?custom = value一样传递有关您可以解析的事务的额外信息。他们的代码会自动找出答案,并在最后加上& crypt =参数。

Note that you don't have to go direct to success.php. You can make it be like success.php?custom=value to pass extra information on the transaction that you can parse. Their code will automatically figure this out and tack on the &crypt= parameter on the end. The same goes with fail.php.

他们确实有办法使SagePay向客户和供应商发送电子邮件,但这实在是太过分了,因为您可以这样做

They do have ways to make SagePay send emails to the customer and to the vendor, but it's really overkill because you can do the same thing in your own PHP code with the mail() statement when doing the order.

参考:请注意,以下文档URL将来可能会更改。要获取最新版本的文档,请访问网站,以开发人员身份注册(过程为1分钟),然后搜索表单协议。

REFERENCE: Note that the following doc URL may change in the future. To get the latest version of the doc, visit the website, enroll as a developer (a 1 minute process), and search on "form protocol".

http://www.sagepay.com/sites/default/files/下载/sagepayformprotocolandintegrationguidelines_0.pdf

编辑:新链接(2017年10月25日)- https://www.sagepay.co.uk/file/25041/download-document /FORM_Integration_and_Protocol_Guidelines_270815.pdf

这篇关于如何制作SagePay BuyNow按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆