Pay with Paypal through Paypal REST API does not show up payment description on Paypal Sandbox or live sites

后端 未结 2 1521
北荒
北荒 2020-12-25 12:06

I am implementing Paypal\'s new REST API Pay with Paypal method that can be referenced here: https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypa

2条回答
  •  甜味超标
    2020-12-25 12:28

    Thank you. Madhu remember to use the rest-api library!

    Details amountDetails = new Details();
                        amountDetails.setSubtotal(autoregistro.getPedido().getItems().get(0).getTotal().toPlainString());
                        amountDetails.setTax("0");
                        amountDetails.setShipping("0");
    
                        Amount amount = new Amount();
                        amount.setCurrency("USD");
                        amount.setTotal(autoregistro.getPedido().getItems().get(0).getTotal().toPlainString());
                        // amount.setTotal("7.47"); // Los decimales deben ser con punto
                        amount.setDetails(amountDetails);
    
                        Item item = new Item();
                        item.setCurrency("USD");
                        item.setQuantity("1");
                        item.setName(autoregistro.getPedido().getItems().get(0).getDescripcion());
                        item.setPrice(amountDetails.getSubtotal());
    
                        List items = new ArrayList();
                        items.add(item);
    
                        ItemList itemList = new ItemList();
                        itemList.setItems(items);
    
                        Transaction transaction = new Transaction();
                        transaction.setDescription(item.getName());
                        transaction.setAmount(amount);
                        transaction.setItemList(itemList);
    
                        List transactions = new ArrayList();
                        transactions.add(transaction);
    
                        Payer payer = new Payer();
                        payer.setPaymentMethod("paypal");
                        // payer.setPaymentMethod("credit_card");
    
                        Payment payment = new Payment();
                        payment.setIntent("sale");
                        payment.setPayer(payer);
                        payment.setTransactions(transactions);
                        RedirectUrls redirectUrls = new RedirectUrls();
                        redirectUrls.setCancelUrl(this.configParameters.getAutoregistroURL() + "/pay_paypal?cancel=true");
                        redirectUrls.setReturnUrl(this.configParameters.getAutoregistroURL() + "/pay_paypal?success=true");
                        payment.setRedirectUrls(redirectUrls);
    
                        Payment createdPayment = payment.create(apiContext);
    

提交回复
热议问题