我创建了一个有0个基金的沙盒个人帐户但是当我在我的应用程序中使用沙盒paypal进行付款时,它仍然成功接受了付款。如何模拟付款拒绝?
注意:它不断恢复其他付款方式,而不是使用paypal资金。它在沙箱帐户中出于某种原因追逐曼哈顿银行和一些转发卡设置。
请求初始令牌的代码
BasicAmountType orderTotal = create(12, false);
AddressType addr = new AddressType();
addr.setPhone(user.getPhone());
addr.setName(user.getName());
PaymentDetailsType paymentDetails = new PaymentDetailsType();
paymentDetails.setPaymentAction(PaymentActionCodeType.fromValue("Sale"));
paymentDetails.setOrderTotal(orderTotal);
paymentDetails.setFulfillmentAddress(addr);
List<PaymentDetailsType> paymentDetailsList = new ArrayList<PaymentDetailsType>();
paymentDetailsList.add(paymentDetails);
SetExpressCheckoutRequestDetailsType setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
Map<String, Object> map = new HashMap<>();
String baseUrl = request.getBase();
String url = baseUrl+Router.reverse("wizards.Setup.confirm", map).url;
String url2 = baseUrl+Router.reverse("wizards.Setup.cancelled", map).url;
setExpressCheckoutRequestDetails.setReturnURL(url);
setExpressCheckoutRequestDetails.setCancelURL(url2);
setExpressCheckoutRequestDetails.setPaymentDetails(paymentDetailsList);
setExpressCheckoutRequestDetails.setLocaleCode(getLangCode());
setExpressCheckoutRequestDetails.setBuyerEmail(user.getEmail());
BillingAgreementDetailsType billingAgreement = new BillingAgreementDetailsType(BillingCodeType.fromValue("RecurringPayments"));
String desc = Messages.get("paypal.product.description");
billingAgreement.setBillingAgreementDescription(desc);
List<BillingAgreementDetailsType> billList = new ArrayList<BillingAgreementDetailsType>();
billList.add(billingAgreement);
setExpressCheckoutRequestDetails.setBillingAgreementDetails(billList);
SetExpressCheckoutRequestType setExpressCheckoutRequest = new SetExpressCheckoutRequestType(setExpressCheckoutRequestDetails);
setExpressCheckoutRequest.setVersion(VERSION);
setExpressCheckoutRequest.setErrorLanguage(getLangCode());
SetExpressCheckoutReq setExpressCheckoutReq = new SetExpressCheckoutReq();
setExpressCheckoutReq.setSetExpressCheckoutRequest(setExpressCheckoutRequest);
Map<String, String> sdkConfig = Utility.getPaypalSdk();
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig);
try {
SetExpressCheckoutResponseType response = service.setExpressCheckout(setExpressCheckoutReq);
AckCodeType ack = response.getAck();
if(ack == AckCodeType.SUCCESS)
return response.getToken();
else if(ack == AckCodeType.SUCCESSWITHWARNING) {
log.warn("warning on start checkout="+response.getErrors()+", ack="+ack+", token="+response.getToken()+", version="+response.getVersion()+" corrId="+response.getCorrelationID());
return response.getToken();
}
throw new RuntimeException("failed to start checkout="+response.getErrors()+", ack="+ack+", token="+response.getToken()+", version="+response.getVersion()+" corrId="+response.getCorrelationID());
} catch (Exception e) {
throw new RuntimeException(e);
}
一旦paypal重定向,这是我的代码,以获得初始和定期付款设置
private static CreateRecurringPaymentsProfileResponseDetailsType collectPayment(String token,
PayPalAPIInterfaceServiceService service, StoreEmployeeDbo emp)
throws Exception {
BasicAmountType amount = create(PRICE, true);
ActivationDetailsType activationDetails = new ActivationDetailsType();
activationDetails.setFailedInitialAmountAction(FailedPaymentActionType.CANCELONFAILURE);
activationDetails.setInitialAmount(amount);
BasicAmountType periodAmt = create(PRICE, false);
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType();
paymentPeriod.setAmount(periodAmt);
paymentPeriod.setBillingFrequency(1);
paymentPeriod.setBillingPeriod(BillingPeriodType.MONTH);
String desc = Messages.get("paypal.product.description");
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType(desc, paymentPeriod);
scheduleDetails.setActivationDetails(activationDetails);
scheduleDetails.setMaxFailedPayments(3);
DateTime dt = new DateTime();
DateTime plusMonths = dt.plusMonths(1);
String dateStr = ""+plusMonths;
RecurringPaymentsProfileDetailsType recurringDetails = new RecurringPaymentsProfileDetailsType();
recurringDetails.setBillingStartDate(dateStr);
recurringDetails.setSubscriberName(emp.getName());
CreateRecurringPaymentsProfileRequestDetailsType profileReq = new CreateRecurringPaymentsProfileRequestDetailsType();
profileReq.setToken(token);
profileReq.setScheduleDetails(scheduleDetails);
profileReq.setRecurringPaymentsProfileDetails(recurringDetails);
CreateRecurringPaymentsProfileRequestType reqType = new CreateRecurringPaymentsProfileRequestType();
reqType.setVersion(VERSION);
reqType.setErrorLanguage(getLangCode());
reqType.setCreateRecurringPaymentsProfileRequestDetails(profileReq);
CreateRecurringPaymentsProfileReq req = new CreateRecurringPaymentsProfileReq();
req.setCreateRecurringPaymentsProfileRequest(reqType);
CreateRecurringPaymentsProfileResponseType response = service.createRecurringPaymentsProfile(req );
AckCodeType ack = response.getAck();
if(ack == AckCodeType.SUCCESSWITHWARNING) {
log.warn("warning on start checkout="+response.getErrors()+", ack="+ack+", version="+response.getVersion()+" corrId="+response.getCorrelationID());
if(response.getCreateRecurringPaymentsProfileResponseDetails() != null) {
CreateRecurringPaymentsProfileResponseDetailsType details = response.getCreateRecurringPaymentsProfileResponseDetails();
log.warn("more info. profileid="+details.getProfileID()+" txid="+details.getTransactionID()+" status="+details.getProfileStatus().getValue());
}
return response.getCreateRecurringPaymentsProfileResponseDetails();
} else if(ack == AckCodeType.SUCCESS) {
return response.getCreateRecurringPaymentsProfileResponseDetails();
}
throw new RuntimeException("failure collecting payment="+response.getErrors()+", ack="+ack+", version="+response.getVersion()+" corrId="+response.getCorrelationID());
}
但这是成功的。
编辑:我开启了否定测试,当我申请PayPal令牌时,我将金额设置为105.37(我尝试过USD和HKD但没有帮助).... //In this code, t7he orderTotal is 105.37 in USD (this is part of the request payment token code
PaymentDetailsType paymentDetails = new PaymentDetailsType();
paymentDetails.setPaymentAction(PaymentActionCodeType.fromValue("Sale"));
paymentDetails.setOrderTotal(orderTotal);
paymentDetails.setFulfillmentAddress(addr);
然后,当用户点击购买时,我设置了定期的个人资料,并将105.37插入初始金额和以下代码中的经常性金额......
//amount variable AND periodAmt variable are setup with 105.37 in USD
ActivationDetailsType activationDetails = new ActivationDetailsType();
activationDetails.setFailedInitialAmountAction(FailedPaymentActionType.CANCELONFAILURE);
activationDetails.setInitialAmount(amount);
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType();
paymentPeriod.setAmount(periodAmt);
paymentPeriod.setBillingFrequency(1);
paymentPeriod.setBillingPeriod(BillingPeriodType.MONTH);
付款仍然成功:(
上面发送的肥皂信息是
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="urn:ebay:api:PayPalAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents"
xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:ed="urn:ebay:apis:EnhancedDataTypes">
<soapenv:Header><ns:RequesterCredentials><ebl:Credentials><ebl:Username>dean-facilitator_api1.xsoftware.biz</ebl:Username>
<ebl:Password>138807XXXX</ebl:Password>
<ebl:Signature>AY.QZJbiiP6AK3cWhljHCEhQtTyzApzADFFNYBR</ebl:Signature></ebl:Credentials>
</ns:RequesterCredentials></soapenv:Header><soapenv:Body>
<ns:CreateRecurringPaymentsProfileReq><ns:CreateRecurringPaymentsProfileRequest>
<ebl:ErrorLanguage>zh_CN</ebl:ErrorLanguage><ebl:Version>104.0</ebl:Version>
<ebl:CreateRecurringPaymentsProfileRequestDetails>
<ebl:Token>EC-0KU028910G908352C</ebl:Token>
<ebl:RecurringPaymentsProfileDetails><ebl:SubscriberName>wert</ebl:SubscriberName><ebl:BillingStartDate>2014-01-29T12:06:17.004-07:00</ebl:BillingStartDate></ebl:RecurringPaymentsProfileDetails><ebl:ScheduleDetails>
<ebl:Description>You will be billed monthly while your store is online and live. You can cancel and close your store at any time.</ebl:Description><ebl:PaymentPeriod><ebl:BillingPeriod>Month</ebl:BillingPeriod>
<ebl:BillingFrequency>1</ebl:BillingFrequency><ebl:Amount currencyID="USD">105.37</ebl:Amount></ebl:PaymentPeriod>
<ebl:MaxFailedPayments>3</ebl:MaxFailedPayments>
<ebl:ActivationDetails><ebl:InitialAmount currencyID="USD">105.37</ebl:InitialAmount>
<ebl:FailedInitialAmountAction>CancelOnFailure</ebl:FailedInitialAmountAction>
</ebl:ActivationDetails></ebl:ScheduleDetails>
</ebl:CreateRecurringPaymentsProfileRequestDetails>
</ns:CreateRecurringPaymentsProfileRequest></ns:CreateRecurringPaymentsProfileReq>
感谢, 迪安
答案 0 :(得分:1)
在http://developer.paypal.com登录您的帐户,然后点击应用程序,然后点击左侧的沙盒帐户。您将在那里看到您的沙箱帐户,每个帐户都有一个小箭头,您可以单击该箭头以获取额外选项。单击箭头,然后单击“配置文件”。弹出配置文件后,单击“设置”,然后打开“否定测试”。
如果在沙盒帐户上启用了否定测试,您可以通过发送与代码匹配的金额来强制执行特定的错误代码。例如,如果要触发错误10537,则在API请求中发送AMT为105.37。