Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Najeeb Arif NajeebArif

💭
I may be slow to respond.
  • Oracle
  • Bangalore, India
View GitHub Profile
View PayPalPaymentServiceV3.java
//...
@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());
}
View OrderControllerV4.java
//...
private String orderId = "";
@GetMapping
public String orderPage(Model model){
model.addAttribute("orderId",orderId);
return "order";
}
View OrderControllerV3.java
//...
@PostMapping
public String placeOrder(@RequestParam Double totalAmount, HttpServletRequest request){
final URI returnUrl = buildReturnUrl(request);
CreatedOrder createdOrder = paymentService.createOrder(totalAmount, returnUrl);
return "redirect:"+createdOrder.getApprovalLink();
}
//...
View PayPalPaymentServiceV2.java
//...
@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);
View PayPalPaymentServiceV1.java
@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));
}
View application.yml
paypal:
clientId: ${paypal.clientId}
clientSecret: ${paypal.secret}
View PaymentServiceV1.java
public interface PaymentService {
CreatedOrder createOrder(Double totalAmount, URI returnUrl);
}
View CreatedOrder.java
@Data
public class CreatedOrder {
private final String orderId;
private final URI approvalLink;
}
View OrderControllerV2.java
//...
private final PaymentService paymentService;
public OrderController(PaymentService paymentService) {
this.paymentService = paymentService;
}
@PostMapping
public String placeOrder(@RequestParam Double totalAmount, HttpServletRequest request){
View OrderControllerV1.java
//...
@GetMapping("/capture")
public String captureOrder(){
return "";
}
@PostMapping
public String placeOrder(@RequestParam Double amountId, HttpServletRequest request){
final URI returnUrl = buildReturnUrl(request);