Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Commit 7151f77

Browse files
committed
Few minor changes in PayPal integration
1 parent 7879901 commit 7151f77

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/main/java/pl/simplemethod/codebin/paypal/PayPalBillingPlan.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public PayPalBillingPlan(APIContext apiContext) {
2121
this.apiContext = apiContext;
2222
}
2323

24-
private static final String CANCEL_URL = "http://localhost/subscribe-failure";
25-
private static final String PROCESS_URL = "http://localhost/subscribe-success";
24+
private static final String CANCEL_URL = "http://127.0.0.1/dashboard/dashboard-payment-error.html";
25+
private static final String PROCESS_URL = "http://127.0.0.1/dashboard/dashboard-payment-accept.html";
2626

2727
/**
2828
* Creates a plan to billing plan

src/main/java/pl/simplemethod/codebin/paypal/PayPalController.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
import com.paypal.api.payments.Agreement;
44
import com.paypal.api.payments.Plan;
55
import com.paypal.base.rest.PayPalRESTException;
6+
import org.json.JSONObject;
67
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.RequestParam;
9-
import org.springframework.web.bind.annotation.RestController;
8+
import org.springframework.http.HttpHeaders;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.MediaType;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.*;
1013

1114
import java.io.UnsupportedEncodingException;
1215
import java.net.MalformedURLException;
1316

1417
@RestController
18+
@RequestMapping("paypal")
1519
public class PayPalController {
1620

1721
private PayPalBillingPlan payPalBillingPlan;
@@ -25,20 +29,27 @@ public PayPalController(PayPalBillingPlan payPalBillingPlan, PayPalBillingAgreem
2529

2630
/**
2731
* Define and create billing plan and billing agreement.
28-
* Redirects response to successful or unsuccessful URL
32+
* Redirects response to returned URL
2933
*/
3034
@GetMapping("/subscribe")
31-
public void subscribe() {
35+
public @ResponseBody ResponseEntity subscribe() {
36+
HttpHeaders headers = new HttpHeaders();
37+
headers.setContentType(MediaType.APPLICATION_JSON);
38+
3239
try {
3340
Plan plan = payPalBillingPlan.create();
3441
Agreement agreement = payPalBillingAgreement.define(plan.getId());
35-
String redirect = payPalBillingAgreement.create(agreement);
36-
// TODO: 02/06/2019 REDIRECT to redirect url
42+
43+
JSONObject body = new JSONObject();
44+
body.put("url", payPalBillingAgreement.create(agreement));
45+
return new ResponseEntity<>(body.toString(), headers, HttpStatus.valueOf(200));
3746
} catch (PayPalRESTException e) {
3847
System.err.println(e.getDetails());
3948
} catch (MalformedURLException | UnsupportedEncodingException e) {
4049
e.printStackTrace();
4150
}
51+
52+
return new ResponseEntity<>("", headers, HttpStatus.BAD_REQUEST);
4253
}
4354

4455
/**

src/main/resources/public/dashboard/dashboard-profile.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ <h3 class="page-title">Premium Plan</h3>
125125
</div>
126126
<span>Do not wait and buy your access right now!</span>
127127
<h4 class="mb-4">Only for <span style="text-decoration: line-through;">$19.99</span> <b>$9.95</b>/month*</h4>
128-
<a href="dashboard-payment-accept.html">
128+
<a href="/paypal/subscribe">
129129
<button type="button" class="mb-5 btn btn-primary mr-2 btn-block"><i class="fab fa-paypal p-1"></i> Buy with PayPal</button>
130130
</a>
131131
</div>

0 commit comments

Comments
 (0)