@@ -29,9 +29,8 @@ public class PayPalController {
29
29
private PayPalBillingPlan payPalBillingPlan ;
30
30
private PayPalBillingAgreement payPalBillingAgreement ;
31
31
32
- private static final String WEBHOOK_ID = "5D129190NJ603512E " ;
32
+ private static final String WEBHOOK_ID = "96044437SH785042F " ;
33
33
34
- private static String planId ;
35
34
private static final String PAYMENT_ACCEPT_URL = "https://127.0.0.1/dashboard.html#!/payment-accept" ;
36
35
37
36
@ Autowired
@@ -52,8 +51,6 @@ public void subscribe(HttpServletResponse response) {
52
51
try {
53
52
Plan plan = payPalBillingPlan .create ();
54
53
Agreement agreement = payPalBillingAgreement .define (plan .getId ());
55
- planId = plan .getId ();
56
-
57
54
response .sendRedirect (payPalBillingAgreement .create (agreement ));
58
55
} catch (PayPalRESTException e ) {
59
56
System .err .println (e .getDetails ());
@@ -71,10 +68,10 @@ public void subscribe(HttpServletResponse response) {
71
68
@ GetMapping ("/payment-success" )
72
69
public void success (HttpServletResponse response , @ RequestParam String token , @ CookieValue ("id" ) Integer id ) {
73
70
try {
74
- payPalBillingAgreement .execute (token );
71
+ Agreement agreement = payPalBillingAgreement .execute (token );
75
72
76
73
Users users = usersRepository .getFirstById (id );
77
- users .setSubscription (planId );
74
+ users .setSubscription (agreement . getId () );
78
75
usersRepository .save (users );
79
76
} catch (PayPalRESTException e ) {
80
77
System .err .println (e .getDetails ());
@@ -94,8 +91,8 @@ public void success(HttpServletResponse response, @RequestParam String token, @C
94
91
JSONObject jsonObject = new JSONObject (payload );
95
92
if (jsonObject .getString ("event_type" ).equals ("BILLING.SUBSCRIPTION.CANCELLED" )) {
96
93
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" );
99
96
} else {
100
97
return new ResponseEntity <>("" , null , HttpStatus .BAD_REQUEST );
101
98
}
0 commit comments