在我的代码中,我正在尝试向Paypal REST API发送所需信息,而Paypal正在向我发送“已批准”状态,但为了完成付款,我需要执行付款。
payment.execute(accesstoken,paymentExecution)
...但我无法从回复中获得payer_id
。
以下是我的代码以获取更多信息,并感谢您的帮助!
public class PaypalPaymentWithCreditCardServlet {
// private static final long serialVersionUID = 734220724945040319L;
// @Override
public void init () throws Exception {
InputStream is = PaypalPaymentWithCreditCardServlet.class.getResourceAsStream("/sdk_config.properties");
try {
PayPalResource.initConfig(is);
} catch (PayPalRESTException e) {
// goto failure page. can't do anything without configuration file
e.printStackTrace();
}
}
public boolean doPost (PaymentPojo paymentpojo) throws Exception {
try {
String accessToken = GenerateAccessToken.getAccessToken();
APIContext apiContext = new APIContext(accessToken);
final Payment payment = new PaymentBuilder().setBillingAddress(paymentpojo.getBillingAddress())
.setCreditCard(paymentpojo.getCreditCard())
.setPaymentDetail(paymentpojo.getDetails())
.setTransactionAmount(paymentpojo.getAmount())
.build();
Payment createdPayment = payment.create(apiContext);
System.out.println(Payment.getLastResponse());
System.out.println(String.format("created payment with id [%s] and status=[%s]", createdPayment.getId(), createdPayment.getState()));
if(!createdPayment.getState().toLowerCase().equalsIgnoreCase(PaypalState.APPROVED.getStatus())) {
// payment is not created. throw an exception
System.out.println("Payment handshake did not go through!!!");
return false;
}
// if it is not created throw exception
// payment.execute(accessToken, paymentExecution);
return true;
} catch (PayPalRESTException e) {
}
return false;
}
}
答案 0 :(得分:0)
对于信用卡付款,payer_id是您用于识别系统中用户的唯一属性(例如电子邮件地址),您每次都会在payerID中提供付款。
如果您不了解用户的信息,例如访客结账,则无需提供付款人ID。
对于paypal付款,始终需要提供payer_id,并在用户批准付款后附加到redirect_url。完整文档位于https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypal-payment/