如何异步调用Square API方法

时间:2019-04-08 06:34:40

标签: angularjs square-connect square

如何异步调用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

1 个答案:

答案 0 :(得分:0)

为了后代,请从评论中拉出。

requestCardNonce是异步的,完成后将调用cardNonceResponseReceived,因此,如果要在函数完成后调用它,则应将其放在cardNonceResponseReceived中。 / p>

相关问题