This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
@Override | |
@SneakyThrows | |
public void captureOrder(String orderId) { | |
final OrdersCaptureRequest ordersCaptureRequest = new OrdersCaptureRequest(orderId); | |
final HttpResponse<Order> httpResponse = payPalHttpClient.execute(ordersCaptureRequest); | |
log.info("Order Capture Status: {}",httpResponse.result().status()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
private String orderId = ""; | |
@GetMapping | |
public String orderPage(Model model){ | |
model.addAttribute("orderId",orderId); | |
return "order"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
@PostMapping | |
public String placeOrder(@RequestParam Double totalAmount, HttpServletRequest request){ | |
final URI returnUrl = buildReturnUrl(request); | |
CreatedOrder createdOrder = paymentService.createOrder(totalAmount, returnUrl); | |
return "redirect:"+createdOrder.getApprovalLink(); | |
} | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
@Override | |
@SneakyThrows | |
public CreatedOrder createOrder(Double totalAmount, URI returnUrl) { | |
final OrderRequest orderRequest = createOrderRequest(totalAmount, returnUrl); | |
final OrdersCreateRequest ordersCreateRequest = new OrdersCreateRequest().requestBody(orderRequest); | |
final HttpResponse<Order> orderHttpResponse = payPalHttpClient.execute(ordersCreateRequest); | |
final Order order = orderHttpResponse.result(); | |
LinkDescription approveUri = extractApprovalLink(order); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class PayPayPaymentService implements PaymentService{ | |
private final PayPalHttpClient payPalHttpClient; | |
public PayPayPaymentService(@Value("${paypal.clientId}") String clientId, | |
@Value("${paypal.clientSecret}") String clientSecret) { | |
payPalHttpClient = new PayPalHttpClient(new PayPalEnvironment.Sandbox(clientId, clientSecret)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paypal: | |
clientId: ${paypal.clientId} | |
clientSecret: ${paypal.secret} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface PaymentService { | |
CreatedOrder createOrder(Double totalAmount, URI returnUrl); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Data | |
public class CreatedOrder { | |
private final String orderId; | |
private final URI approvalLink; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
private final PaymentService paymentService; | |
public OrderController(PaymentService paymentService) { | |
this.paymentService = paymentService; | |
} | |
@PostMapping | |
public String placeOrder(@RequestParam Double totalAmount, HttpServletRequest request){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
@GetMapping("/capture") | |
public String captureOrder(){ | |
return ""; | |
} | |
@PostMapping | |
public String placeOrder(@RequestParam Double amountId, HttpServletRequest request){ | |
final URI returnUrl = buildReturnUrl(request); |