我的问题是,每当我点击页面上的paypal按钮时,它会弹出一下,然后会出现403禁止错误。这个问题离我的问题Why do I keep getting a 403 forbidden with PayPal?最近,但不同,因为我使用的是角色。
这是我的角度代码的相关部分:
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