Search code examples
angularpaypalpaypal-sandboxpaypal-ipnpaypal-subscriptions

Paypal subscription integration and revise subscription issues


I'm working with angular project where my requirement is to configure paypal payment gateway with create subscription, cancel subscription, upgrade subscription.

I'm having 2 problem with paypal as described below:

1) I've successfully Rendered paypal button with below code:

index.html

<script src="https://www.paypal.com/sdk/js?client-id=client_id_here&disable-funding=credit,card&vault=true"></script>

payment.component.ts

const self = this;  
this.planId = localStorage.getItem("paypalPlanId");  //Default Plan Id

paypal.Buttons({  
  createSubscription: function (data, actions) {  
    
    return actions.subscription.create({  
      'plan_id': self.planId,
      "subscriber": {
        "name": {
          "given_name": localStorage.getItem("fullName").split(' ')[0],
          "surname": localStorage.getItem("fullName").split(' ')[1]
        },
        "email_address": localStorage.getItem("email")
      }
    });  
  },
  onApprove: function (data) {  
    console.log(data); 
    self.getSubcriptionDetails();
    self.router.navigate(CC_GLOBAL.PAYMENT_THANKS_ROUTE);
  },  
  onCancel: function (data) {  
    // Show a cancel page, or return to cart  
    console.log(data);  
  },  
  onError: function (err) {  
    // Show an error page here, when an error occurs  
    console.log(err);  
  }  

}).render(this.paypalElement.nativeElement);

Above code is working as expected and able to create subscription. Now my requirement is quite different, as mentioned below:

After clicking on paypal button, it is opening modal popup and after successful login attempt I'm able to subscribe plan.

I've also setup webhook methods with my account, after successful subscription it is calling webhook methods and while calling webhook method response is being return with loggedIn user details (EMAIL, first/last name) instead of above email and user first/last name.

Above createSubscription method working as expected sometimes but sometimes it's not.

Got reference of above code from official doc of paypal.

2) Paypal upgrade plan REST API returns an error:

I'm having subscription id and taken reference from here:

https://developer.paypal.com/docs/business/subscriptions/add-capabilities/revise-subscriptions/

but is's returning below error:

Invalid subscription status for revise action; subscription status should be active.

how could I know about active status, I'm using Sandbox account


Solution

  • Here I did some research on this questions and found below paypal bugs:

    1) https://github.com/paypal/paypal-checkout-components/issues/1336

    2) https://github.com/paypal/paypal-checkout-components/issues/1247#issuecomment-551066663

    Still I'm looking for answer for the same.