首页 > 解决方案 > 贝宝结帐 | 403 禁止错误

问题描述

我的问题是每次单击页面上的贝宝按钮时,它都会短暂弹出,然后给出 403 禁止错误。这个问题与我的问题最接近为什么我一直收到 PayPal 禁止的 403?但不同,因为我使用的是角度。

这是我的角度代码的相关部分:

import { Component, OnInit, AfterViewChecked } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { ShoppingCartService} from '../shopping-cart.service';
import { PaymentsService } from '../payments.service';
import { environment } from '../../environments/environment';
import { StripeToken } from 'stripe-angular';

declare let paypal: any;

@Component({
  selector: 'app-cartpage',
  templateUrl: './cartpage.component.html',
  styleUrls: ['./cartpage.component.css']
})
export class CartpageComponent implements OnInit, AfterViewChecked {

cartItems;
id = localStorage.getItem('cartId');
storage: any = [];
addToCart = [];
parents: any = [];
total = 0;
number: any = 0;
handler: any;
amount: 500;
addScript: boolean = false;
finalAmount: number = this.total;

paypalConfig = {
  env: 'sandbox',
  client: {
    sandbox: 'my-key',
    production: 'my-key'
  },
  commit: true,
  payment : (data, actions) => {
    return actions.payment.create({
      payment: {
        transactions: [
          { amount: {total: this.finalAmount, currency: 'USD' } }
        ]
      }
    })
  },
  onAuthorize: (data, actions) => {
    return actions.payment.execute().then((payment)=>{
      //do something when payment is successful
    })
  }
};

ngAfterViewChecked() : void {
  if(!this.addScript) {
    this.addPaypalScript().then(() => {
      paypal.Button.render(this.paypalConfig, '#paypal-checkout-button')
    })
  }
}

addPaypalScript() {
  this.addScript = true;
  return new Promise((resolve, reject) => {
    let scriptTagElement = document.createElement('script');
    scriptTagElement.src = "https://www.paypalobjects.com/api/checkout.js";
    scriptTagElement.onload = resolve;
    document.body.appendChild(scriptTagElement);
  })
}

这是我在控制台中的错误:

POST https://www.sandbox.paypal.com/v1/payments/payment 403(禁止)

未捕获的错误:错误:发布https://www.sandbox.paypal.com/v1/payments/payment的请求 失败,出现 403 错误。相关 ID:3ef24e19eb852、3ef24e19eb852

{
     "name": "PERMISSION_DENIED",
     "message": "No permission for the requested operation",
     "information_link": https://developer.paypal.com/docs/api/payments/#errors",
     "debug_id": "3ef24e19eb852" 
}

任何帮助或有用的帖子/文章将不胜感激,谢谢

更新 5/05/2018 Paypal 仍未解决此问题。但是,如果您想检查是否已正确设置所有内容,则可以使用 paypal 的沙箱凭据对其进行测试。https://developer.paypal.com/demo/checkout/#/pattern/client

标签: angularpaypalcheckouthttp-status-code-403

解决方案


推荐阅读