@@ -29,9 +29,8 @@ public class PayPalController {
2929 private PayPalBillingPlan payPalBillingPlan ;
3030 private PayPalBillingAgreement payPalBillingAgreement ;
3131
32- private static final String WEBHOOK_ID = "5D129190NJ603512E " ;
32+ private static final String WEBHOOK_ID = "96044437SH785042F " ;
3333
34- private static String planId ;
3534 private static final String PAYMENT_ACCEPT_URL = "https://127.0.0.1/dashboard.html#!/payment-accept" ;
3635
3736 @ Autowired
@@ -52,8 +51,6 @@ public void subscribe(HttpServletResponse response) {
5251 try {
5352 Plan plan = payPalBillingPlan .create ();
5453 Agreement agreement = payPalBillingAgreement .define (plan .getId ());
55- planId = plan .getId ();
56-
5754 response .sendRedirect (payPalBillingAgreement .create (agreement ));
5855 } catch (PayPalRESTException e ) {
5956 System .err .println (e .getDetails ());
@@ -71,10 +68,10 @@ public void subscribe(HttpServletResponse response) {
7168 @ GetMapping ("/payment-success" )
7269 public void success (HttpServletResponse response , @ RequestParam String token , @ CookieValue ("id" ) Integer id ) {
7370 try {
74- payPalBillingAgreement .execute (token );
71+ Agreement agreement = payPalBillingAgreement .execute (token );
7572
7673 Users users = usersRepository .getFirstById (id );
77- users .setSubscription (planId );
74+ users .setSubscription (agreement . getId () );
7875 usersRepository .save (users );
7976 } catch (PayPalRESTException e ) {
8077 System .err .println (e .getDetails ());
@@ -94,8 +91,8 @@ public void success(HttpServletResponse response, @RequestParam String token, @C
9491 JSONObject jsonObject = new JSONObject (payload );
9592 if (jsonObject .getString ("event_type" ).equals ("BILLING.SUBSCRIPTION.CANCELLED" )) {
9693 JSONObject resource = (JSONObject ) jsonObject .get ("resource" );
97- usersRepository .updatePlan (resource .getString ("plan_id " ));
98- System .err .println (resource .getString ("plan_id " ) + " - subscription cancelled" );
94+ usersRepository .updatePlan (resource .getString ("id " ));
95+ System .err .println (resource .getString ("id " ) + " - subscription cancelled" );
9996 } else {
10097 return new ResponseEntity <>("" , null , HttpStatus .BAD_REQUEST );
10198 }
0 commit comments