3

My issue is every time I click the paypal button on my page, it pops up briefly then gives a 403 forbidden error. This question is the closest to my issue Why do I keep getting a 403 forbidden with PayPal? but different because I'm using angular.

This is the relevant part of my angular code:

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);
  })
}

this is my error in the console:

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

Uncaught Error: Error: Request to post https://www.sandbox.paypal.com/v1/payments/payment failed with 403 error. Correlation 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" 
}

any help or useful posts/articles to read would be appreciated, Thanks

UPDATE 5/05/2018 Paypal still hasn't fixed this issue. But if you want to check that you have everything set up correctly you can use paypal's sandbox credentials to test it. https://developer.paypal.com/demo/checkout/#/pattern/client

Dre Jackson
  • 771
  • 10
  • 18
  • 1
    Why give it a down vote? I am new to angular and just trying to understand how to implement paypal Check out. All of the information that is needed to answer this question is provided, there is also no similar questions to my knowledge of someone with this exact issue (and corresponding error code) I dont know why you would down vote when this will not only help me but someone in the future. If I am not providing enough information say that, because I may not have the understanding you do so there may be something I don't understand that's so simple to you. Anyway, thanks again – Dre Jackson Jun 01 '18 at 16:09
  • check your credentials. You do not have permission for your paypal request. – AussieJoe Jun 01 '18 at 16:18
  • You need to fill out your paypal client keys. This is a typical response when you are not authorized to make the request. – bc1105 Jun 01 '18 at 16:20
  • I'm sorry for the misunderstanding, I did fill out the client keys, I just used 'my-key' as a filler. The client keys still give this error. – Dre Jackson Jun 01 '18 at 16:32
  • I also checked my permissions, and everything is enabled, so I am not sure why I am getting this error. The debug IDs are provided, but to my knowledge you can't do much with them. I contacted Paypal to try to resolve this issue. I think it's a Paypal issue. Thanks again yall – Dre Jackson Jun 01 '18 at 16:34
  • 1
    Check [Issue #703 :: Getting a 403 - permission_denied error](https://github.com/paypal/paypal-checkout/issues/703). – wchiquito Jun 01 '18 at 17:20
  • 2
    I contacted Paypal and they informed me that it is an issue on their end that they are trying to fix. – Dre Jackson Jun 01 '18 at 18:08
  • Thank for having this question posted... And thanks for the issue report link. And you know how many time you saved me ;) – Louys Patrice Bessette Jun 04 '18 at 20:27
  • haha no problem Louys. Im always asking questions trying to gain better understanding. Doesn't look like paypal fixed it yet either – Dre Jackson Jun 06 '18 at 01:37

0 Answers0