简体   繁体   English

使用AngularJS进行Paypal Express结帐

[英]Paypal Express Checkout with AngularJS

Has anyone had success integrating the PayPal Express Checkout API into an AngularJS web app? 是否有人成功将PayPal Express Checkout API集成到AngularJS Web应用程序中? I have tried to adapt the "in-context" integration steps into my angular site; 我试图将“上下文”集成步骤调整到我的角度站点中。 however, it only works properly once. 但是,它只能正常运行一次。

My scenario is this: 我的情况是这样的:

  • I have the paypal button on a page 我在页面上有贝宝按钮
  • Clicking the paypal button calls paypal.checkout.initXO() , and then makes a server-side call to generate an express checkout token 单击paypal按钮将调用paypal.checkout.initXO() ,然后进行服务器端调用以生成快速结账令牌
  • When the call returns, I pass the token into paypal.checkout.startFlow(tokenFromServer) 通话返回时,我将令牌传递到paypal.checkout.startFlow(tokenFromServer)
  • The PayPal API creates a popup and collects my paypal account info PayPal API创建一个弹出窗口并收集我的Paypal帐户信息
  • The browser gets navigated to my confirm page based on what I set up server-side when I generated the express checkout token. 根据我在生成快速结账令牌时在服务器端设置的内容,浏览器导航到我的确认页面。

As I said above, this works fine once; 就像我在上面说的那样,这可以正常工作一次; the PayPal API navigates the browser to my confirmation page just as I expect. PayPal API会按照我的期望将浏览器导航到我的确认页面。 However, subsequent attempts to use the express checkout API don't navigate the browser after finishing with the paypal popup window. 但是,在完成贝宝弹出窗口后,随后尝试使用Express Checkout API的操作不会导航浏览器。 Refreshing the browser allows me to use express checkout again, once. 刷新浏览器使我可以再次使用快速结帐。

I'm not seeing any errors in the Javascript console. 我在Javascript控制台中没有看到任何错误。

In the meantime I've added this to the ui.router state that is the start point of my "purchase" workflow: 同时,我将其添加到ui.router状态,这是我的“购买”工作流程的起点:

.state("example.buy.the.thing", {
    url: "/buy",
    templateUrl: "path/to/my/template.html",
    controller: ["$window", ($window) => {
        if ($window.needsPaypalRefresh) {
            $window.location.reload();
        }
        $window.needsPaypalRefresh = true;
    }]
})

It refreshes the page on subsequent visits to this state, which resets the PayPal API. 下次访问此状态时,它将刷新页面,从而重置PayPal API。 It works. 有用。 It's ugly, but it works. 很难看,但是可以用。

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

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