Итак, я создал очень простую программу с помощью api docs PayPal.Код довольно прост.Программа работает правильно, как и должна, даже показывает ответ об успешном выполнении, когда платеж выполнен через URL-адрес возврата.
Но сумма не добавляется со счета продавца на счет продавца.Любая помощь будет оценена.Спасибо!
@GetMapping()
public String paypalPay(HttpServletRequest req) {
String redirectUrl = null;
APIContext apiContext = new APIContext(clientID, clientSecret, mode);
// Set payment details
Details details = new Details();
details.setShipping("1");
details.setSubtotal("5");
details.setTax("1");
// Payment amount
Amount amount = new Amount();
amount.setCurrency("USD");
// Total must be equal to sum of shipping, tax and subtotal.
amount.setTotal("7");
amount.setDetails(details);
// Transaction information
Transaction transaction = new Transaction();
transaction.setAmount(amount);
transaction.setDescription("This is the payment transaction description.");
// ### Items
Item item = new Item();
item.setName("Ground Coffee 40 oz").setQuantity("1").setCurrency("USD").setPrice("5");
ItemList itemList = new ItemList();
List<Item> items = new ArrayList<Item>();
items.add(item);
itemList.setItems(items);
transaction.setItemList(itemList);
// The Payment creation API requires a list of
// Transaction; add the created `Transaction`
// to a List
List<Transaction> transactions = new ArrayList<Transaction>();
transactions.add(transaction);
// ###Payer
// A resource representing a Payer that funds a payment
// Payment Method
// as 'paypal'
Payer payer = new Payer();
payer.setPaymentMethod("paypal");
// Add payment details
Payment payment = new Payment();
payment.setIntent("sale");
payment.setPayer(payer);
// payment.setRedirectUrls(redirectUrls);
payment.setTransactions(transactions);
// ###Redirect URLs
RedirectUrls redirectUrls = new RedirectUrls();
String guid = UUID.randomUUID().toString().replaceAll("-", "");
redirectUrls.setCancelUrl(req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
+ req.getContextPath() + "/paypal/payment/cancel?guid=" + guid);
redirectUrls.setReturnUrl(req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
+ req.getContextPath() + "/paypal/payment/success?guid=" + guid);
payment.setRedirectUrls(redirectUrls);
// Create payment
try {
Payment createdPayment = payment.create(apiContext);
// ###Payment Approval Url
Iterator<Links> links = createdPayment.getLinks().iterator();
while (links.hasNext()) {
Links link = links.next();
if (link.getRel().equalsIgnoreCase("approval_url")) {
redirectUrl = link.getHref();
}
}
} catch (PayPalRESTException e) {
System.err.println(e.getDetails());
return "redirect:/paypal/error";
}
if (redirectUrl != null) {
return "redirect:" + redirectUrl;
} else {
return "redirect:/paypal/error";
}
}
@GetMapping("/payment/success")
@ResponseBody
public String executePayment(HttpServletRequest req) {
APIContext apiContext = new APIContext(clientID, clientSecret, mode);
Payment payment = new Payment();
payment.setId(req.getParameter("paymentId"));
PaymentExecution paymentExecution = new PaymentExecution();
paymentExecution.setPayerId(req.getParameter("PayerID"));
try {
Payment createdPayment = payment.execute(apiContext, paymentExecution);
System.out.println(createdPayment);
return "Success";
} catch (PayPalRESTException e) {
System.err.println(e.getDetails());
return "Failed";
}
}