【问题标题】:How to call Square API method asynchronously如何异步调用 Square API 方法
【发布时间】:2019-04-08 06:34:39
【问题描述】:

如何异步调用paymentForm.requestCardNonce()方法

我在 AngularJs 中集成方形支付网关,现在我必须调用 paymentForm.requestCardNonce() 并且此方法在后台调用 Web 服务。现在我必须等待后台呼叫才能继续进行进一步的处理。那么我该如何处理来自 Square Payment Gateway https://docs.connect.squareup.com/payments/sqpaymentform/setup 提供的 paymentForm.requestCardNonce() 方法的回调

初始化代码示例

var paymentForm = new SqPaymentForm({
    applicationId: "sandbox-xxx-xxxxxxxxxxxx",
    inputClass: 'sq-input',
    callbacks: {
        cardNonceResponseReceived: function (errors, nonce, cardData, billingContact, shippingContact) {
        // I am receiving response of web service Here
        }
    }
}

如何通过调用自定义函数中的方法获得成功响应?(注意 - 它的工作和调用方法也可以,但我必须根据来自 Web 服务的响应执行后续步骤)

addCard = function () {
   paymentForm.requestCardNonce();
   // Till this function executes I need to wait here. how can I write promise here ?
}

参考链接 https://docs.connect.squareup.com/payments/sqpaymentform/how-it-works

https://github.com/square/connect-api-examples/tree/master/templates/web-ui/payment-form/basic

【问题讨论】:

  • 您介意解释一下您要做什么吗? requestCardNonce是异步的,当它完成时会调用cardNonceResponseReceived,所以如果你想在完成后调用一个函数,你应该把它放在cardNonceResponseReceived中。
  • 嗨@sjosey,正如你所解释的,我已经实现并且它有效!我已将下一个执行代码添加到另一个函数并在cardNonceResponseReceived 中调用。谢谢
  • 任何人都知道,可以通过 Square 和 Magento 1.x 进行实时库存同步吗?

标签: angularjs square-connect square


【解决方案1】:

为了后代,从cmets中拉出来。

requestCardNonce是异步的,当它完成时会调用cardNonceResponseReceived,所以如果你想在完成后调用一个函数,你应该把它放在cardNonceResponseReceived中。

【讨论】:

    猜你喜欢
    • 2020-03-10
    • 1970-01-01
    • 2019-06-13
    • 2017-03-06
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    相关资源
    最近更新 更多