简体   繁体   中英

PayPal integration in spring boot rest api only

I am trying to integrate PayPal in spring boot app using this link, https://developer.paypal.com/docs/api/quickstart/payments/#define-payment but getting exception like bellow:

2021-03-17 18:37:43.283  INFO 2932 --- [nio-9001-exec-1] d.b.o.controller.PaypalEndpoint          : EXception occred
response-code: 400  details: name: INTERNAL_SERVICE_ERROR   message: An internal service error has occurred details: [] debug-id: cb8b4f5808cef information-link: https://developer.paypal.com/docs/api/payments/#errors
    at com.paypal.base.rest.PayPalRESTException.createFromHttpErrorException(PayPalRESTException.java:72)
    at com.paypal.base.rest.PayPalResource.execute(PayPalResource.java:431)
    at com.paypal.base.rest.PayPalResource.configureAndExecute(PayPalResource.java:295)
    at com.paypal.base.rest.PayPalResource.configureAndExecute(PayPalResource.java:228)
    at com.paypal.api.payments.Payment.create(Payment.java:149)


public Payment createPayment(
            Double total,
            String currency,
            String method,
            String intent,
            String description,
            String cancelUrl,
            String successUrl) throws PayPalRESTException{

        Details details = new Details();
        details.setShipping("1");
        details.setSubtotal("1");
        details.setTax("1");

        Amount amount = new Amount();
        amount.setCurrency(currency);

        total = new BigDecimal(total).setScale(2, RoundingMode.HALF_UP).doubleValue();
        amount.setTotal(String.format("%.2f", total));
        amount.setDetails(details);

        Transaction transaction = new Transaction();
        transaction.setDescription(description);
        transaction.setAmount(amount);

        List<Transaction> transactions = new ArrayList<>();
        transactions.add(transaction);

        Payer payer = new Payer();
        payer.setPaymentMethod(method);

        Payment payment = new Payment();
        payment.setIntent(intent);
        payment.setPayer(payer);
        payment.setTransactions(transactions);
        RedirectUrls redirectUrls = new RedirectUrls();
        redirectUrls.setCancelUrl(cancelUrl);
        redirectUrls.setReturnUrl(successUrl);
        payment.setRedirectUrls(redirectUrls);

        return payment.create(apiContext);
    }

I think exception is occurred in

return payment.create(apiContext);

apiContext have value. Can any body tell me what is the issue?

You are attempting to use a deprecated API that should not be used for any new integration.

Integrate with the REST v2/checkout/orders instead. See 'Create Order' and 'Capture Order' at https://developer.paypal.com/docs/business/checkout/server-side-api-calls/#server-side-api-calls

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM