繁体   English   中英

PayFast-沙盒网站上的订阅取消

[英]PayFast - Subscription cancellation on sandbox site

如何将取消订阅远程发布到PayFast沙箱站点?

假定使用Ajax PUT或Form PUT。

 <form action="https://api.payfast.co.za/subscription/d776203c-341e-c12d-16cb-aa8872d5edee/cancel?testing=true" method="PUT"> <input type="hidden" name="merchant_id" value="10007713"><input type="hidden" name="merchant_key" value="hagd8cby0yk5o"><input type="hidden" name="return_url" value="https://fraternate.herokuapp.com/payment_finished"><input type="hidden" name="cancel_url" value="https://fraternate.herokuapp.com/payment_cancelled"><input type="hidden" name="notify_url" value="https://fraternate.herokuapp.com/payment_notify"><input type="hidden" name="name_first" value="Bob"><input type="hidden" name="name_last" value="Smith"><input type="hidden" name="email_address" value="s@gmail.com"><input type="hidden" name="m_payment_id" value="FAKE5551234"><input type="hidden" name="amount" value="1080.00"><input type="hidden" name="item_name" value="Single User - Subscription"><input type="hidden" name="item_description" value=""><input type="hidden" name="email_confirmation" value="1"><input type="hidden" name="confirmation_address" value="s@gmail.com"><input type="hidden" name="subscription_type" value="1"><input type="hidden" name="frequency" value="6"><input type="hidden" name="cycles" value="0"><input type="hidden" name="custom_str1" value="s@gmail.com"><input type="hidden" name="custom_str2" value="595b8b63dfbafe053c10e425"> <button type="submit">submit</button> </form> 

要么

 $.ajax({ type: "PUT", /* or type:"GET" or type:"PUT" */ crossDomain: true, url: 'https://sandbox.payfast.co.za/sb/subs/cancel/f0d6c3bf-223a-958f-e4dd-5c37ef87821b?merchant_id=10007713&merchant_key=hagd8cby0yk5o&return_url=https%3A%2F%2Ffraternate.herokuapp.com%2Fpayment_finished&cancel_url=https%3A%2F%2Ffraternate.herokuapp.com%2Fpayment_cancelled&notify_url=https%3A%2F%2Ffraternate.herokuapp.com%2Fpayment_notify&name_first=Bob&name_last=Smith&email_address=sd%40gmail.com&m_payment_id=FAKE5551234&amount=1080.00&item_name=Single+User+-+Subscription&item_description=&email_confirmation=1&confirmation_address=sd%40gmail.com&subscription_type=1&frequency=6&cycles=0&custom_str1=sd%40gmail.com&custom_str2=595b8b63dfbafe053c10e425', success: function(data){ console.log('data',) }, error:function(err){ console.log(err) } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

但是,这些选项都不起作用。

有许多可能的URL:

https://sandbox.payfast.co.za/sb/subs/cancel/d776203c-341e-c12d-16cb-aa8872d5edee
https://api.payfast.co.za/[endpoint]/[token]/[action]?testing=true
https://sandbox.payfast.co.za/subscriptions/d776203c-341e-c12d-16cb-aa8872d5edee/cancel

但是这些项目没有成功。 似乎需要使用商人id,令牌和订阅将某种报头信息传递到PUT调用中。 但是,没有样本就很难复制。

任何与沙盒API取消订阅网址发布有关的帮助将不胜感激。

要对此进行更新,仍然无法正常工作,但还有其他进展。

为了解决跨部门问题,服务器需要发布并获取。 这是通过npm require完成的。

var request = require('request'); // http requests
var moment = require('moment'); // timestamp

详细信息是针对沙盒上的商家帐户的

Merchant ID :10007713

遵循developerkit API集成说明的详细信息。 (主要假设https://sandbox.payfast.co.za/eng/process = https://api.payfast.co.za/

var timestamp = moment().toISOString();

request.get('https://https://sandbox.payfast.co.za/eng/process/subscriptions/ping', function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

request.get('https://https://sandbox.payfast.co.za/eng/process/subscriptions/f0d6c3bf-223a-958f-e4dd-5c37ef87821b/ping', function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

request.get('https://https://sandbox.payfast.co.za/eng/process/subscriptions/f0d6c3bf-223a-958f-e4dd-5c37ef87821b/ping?merchant_id=10007713&version=v1&timestamp=&'+timestamp+'&signature=dc4a98c5b5ee17540be5ea5cf458efa7', function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

request.put('https://https://sandbox.payfast.co.za/eng/process/subscriptions/f0d6c3bf-223a-958f-e4dd-5c37ef87821b/cancel?merchant_id=10007713&version=v1&timestamp=&'+timestamp+'&signature=dc4a98c5b5ee17540be5ea5cf458efa7', function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

request.put('https://https://sandbox.payfast.co.za/eng/process/subscriptions/f0d6c3bf-223a-958f-e4dd-5c37ef87821b/cancel:80?merchant_id=10007713&version=v1&timestamp=&'+timestamp+'&signature=dc4a98c5b5ee17540be5ea5cf458efa7', function (error, response, body) {
  console.log('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

以上所有内容均经过测试,但未成功。 尝试了沙盒和api的各种迭代以及测试。 全部返回沙盒上的443错误,而取消订阅则返回404或401。

该请求的任何帮助或示例都将非常有用。

PayFast API服务器不允许跨源资源共享(CORS)。

这意味着在进行ajax调用时,由JQuery执行的飞行前检查将失败,因为服务器响应不包含“ Access-Control-Allow-Origin”标头。

下面也不会在你的Ajax调用API PayFast 工作

dataType: "json",
jsonp: false,
cache: true,
crossDomain: true,

您需要对服务器端脚本执行ajax调用 ,然后再调用PayFast API。 然后,您可以检查ajax成功中API调用的结果,以向用户提供适当的反馈。

404响应表示未找到您的端点(错误的URL),沙箱的正确的API取消端点是:

https://api.payfast.co.za/subscriptions/[your sub token]/cancel?testing=true

查看PayFast文档 ,了解应如何构建端点以及API响应的含义(即401-商家授权失败)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM