如何在RESTful集成中正确授权Paypal信用卡付款?

时间:2018-07-12 10:44:36

标签: paypal paypal-sandbox paypal-rest-sdk

我正在C#中进行PayPal的RESTful集成

我正在尝试使用credit card作为payment_method创建付款。

到目前为止,我已经有了Angular配置,并且可以在我的api Create方法中成功创建并获得状态为“ authorized”的授权响应:

createdPayment = payment.Create(apiContext);

return createdPayment;

然后:

Authorization authorization = payment.transactions[0].related_resources[0].authorization;

authorization状态为 authorized

但是我在控制台中得到响应:

ppxo_no_token_passed_to_payment 
Object { timestamp: 1531389390897, windowID: "8b6e6d498f", pageID: "60540ae7ab", prev_corr_ids: "", referer: "localhost:63809", host: "localhost:63809", path: "/order", env: "production", country: "US", lang: "en", … }

(如果我使用的是沙箱,还不确定它会说env: production吗?)

和:

No value passed to payment

当我单击付款对象的确认链接(例如https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RD0371739881292ULNDSPRA)时,我得到的是json:

name    "AUTHENTICATION_FAILURE"
message "Authentication failed due to invalid authentication credentials or a missing Authorization header."
links   
0   
href    "https://developer.paypal.com/docs/api/overview/#error"
rel "information_link"

因此付款实际上失败了。

我转到提供的引用链接:https://developer.paypal.com/docs/api/overview/#error,发现与访问令牌相关的问题通常会导致身份验证错误,但是我却遇到了 Bearer 成功创建付款后的令牌。

问题是我应该如何使用 Bearer 令牌?在按钮配置的payment方法中返回什么?如何传递给配置的onAuthorize方法(如果有)?以及如何成功授权付款?

我试图通过贝宝(Paypal)API寻找解决方案,但到目前为止没有找到任何答案。

我的角度配置:

paypalConfig = {
    env: 'sandbox',
    client: {
        sandbox: 'my sandbox key'
    },
    commit: true,
    payment: (data: any, actions: any) => {
        // 2. Make a request to your server
        var url = '/paypal/create/';

        return actions.request.post(url)
            .then(function (res: any) {
                    // What HERE?
                    return res.id; // if I return payment id then I get redirected to paypal.com where it obviously says the transation is invalid because I'm doing the process in sandbox not live env
            });
    },
    onAuthorize: (data: any, actions: any) => {
        // WHAT HERE??
        // normally I'd do a request to paypal with paymentid and payerid (https://developer.paypal.com/docs/checkout/how-to/server-integration/#1-set-up-your-client-to-call-your-server) but in case of credit_card payment I don't get those
    }
};

我的Create方法基于此处提供的CreatePayment-唯一的区别是我使用payment_method = "credit_card"(而不是 paypal ),并且我返回了{ {1}}对象可以返回角度,而不是重定向到批准网址。

按钮配置需要

Btw Payment方法。通常,使用贝宝(Paypal)资金时,我会将onAuthorizepaymentId发回贝宝(Paypal)以授权付款,但是如果采用信用卡方式,我会在payerId功能内获得已授权的付款。唯一的问题是它失败了。

0 个答案:

没有答案