Я могу совершать платежи с помощью API PayPal, но когда я посмотрел на квитанцию,
название магазина — «Test Store», можно ли это изменить?
введите здесь описание изображения
Я попробовал изменить имя на странице с информацией о моей компании, но оно по-прежнему отображается как
"Тестовый магазин".
введите здесь описание изображения
Вот как выглядит мой код:
public class PaypalPaymentClient {
private final String paypalClientId;
private final String paypalClientSecret;
private final CreditBundleRepository creditBundleRepository;
//TODO: Refactor redirect urls.
public PaypalPaymentClient(String paypalClientId, String paypalClientSecret, CreditBundleRepository creditBundleRepository) {
this.paypalClientId = paypalClientId;
this.paypalClientSecret = paypalClientSecret;
this.creditBundleRepository = creditBundleRepository;
}
public PaypalCompletePaymentResponse completePayment(PaypalCompletePaymentRequest request) throws PaypalPaymentException {
Payment payment = new Payment();
payment.setId(request.getPaymentId());
PaymentExecution paymentExecution = new PaymentExecution();
paymentExecution.setPayerId(request.getPayerId());
PaypalCompletePaymentResponse response = new PaypalCompletePaymentResponse();
try {
APIContext context = new APIContext(paypalClientId, paypalClientSecret, "sandbox");
Payment createdPayment = payment.execute(context, paymentExecution);
if(createdPayment != null) {
log.info("Successfully completed paypal payment with payment ID: {}", createdPayment.getId());
response.setStatus("success");
}
} catch (PayPalRESTException exception) {
log.error("Failed to complete paypal payment due to exception: {}", exception);
throw new PaypalPaymentException("Failed to complete paypal payment.");
}
return response;
}
public PaypalPaymentResponse createPayment(PaypalPaymentRequest paymentRequest) throws PaypalPaymentException {
PaypalPaymentResponse response = new PaypalPaymentResponse();
Payment payment = getPayment(paymentRequest);
try {
String redirectUrl = "";
APIContext context = new APIContext(paypalClientId, paypalClientSecret, "sandbox");
Payment createdPayment = payment.create(context);
if(createdPayment != null) {
List links = createdPayment.getLinks();
for(Links link:links) {
if(link.getRel().equals("approval_url")) {
redirectUrl = link.getHref();
break;
}
}
response.setStatus("success");
response.setRedirectUrl(redirectUrl);
}
} catch (PayPalRESTException exception) {
log.error("Failed to create paypal payment due to exception: {}", exception);
throw new PaypalPaymentException("Failed to create paypal payment.");
}
return response;
}
private Payment getPayment(PaypalPaymentRequest paymentRequest) throws PaypalPaymentException {
Amount amount = new Amount();
amount.setCurrency(paymentRequest.getCurrency().toString());
amount.setTotal(paymentRequest.getTotalCost().toString());
Transaction transaction = new Transaction();
transaction.setAmount(amount);
transaction.setDescription(getCreditBundleName(paymentRequest.getCreditBundleId()));
List transactionList = new ArrayList();
transactionList.add(transaction);
Payer payer = new Payer();
payer.setPaymentMethod("paypal");
Payment payment = new Payment();
payment.setIntent("sale");
payment.setPayer(payer);
payment.setTransactions(transactionList);
RedirectUrls redirectUrls = new RedirectUrls();
redirectUrls.setCancelUrl("http://localhost:4200/buy-credits");
redirectUrls.setReturnUrl("http://localhost:4200/complete-payment");
payment.setRedirectUrls(redirectUrls);
return payment;
}
private String getCreditBundleName(UUID creditBundleId) throws PaypalPaymentException {
log.info("Finding credit bundle: {}", creditBundleId);
Optional creditBundleOptional = creditBundleRepository.findById(creditBundleId);
if(creditBundleOptional.isPresent()) {
return creditBundleOptional.get().getName();
}
throw new PaypalPaymentException("Credit bundle not found.");
}
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... paypal-api