java paypal商家sdk定期付款无效令牌

时间:2014-04-05 22:41:06

标签: java paypal-sandbox paypal-subscriptions paypal

您好我正在尝试使用JAVA Merhant SDK创建一个Paypal Recurring Pyament,但在尝试调用“createRecurringPaymentsProfile”方法时,我一直有“无效令牌”。

以下是请求和响应

对于SetExpressCheckout请求

 <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>XXX</ebl:Username>
            <ebl:Password>XXX</ebl:Password>
            <ebl:Signature>XXX</ebl:Signature>
        </ebl:Credentials>
    </ns:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
    <ns:SetExpressCheckoutReq>
        <ns:SetExpressCheckoutRequest>
            <ebl:Version>109.0</ebl:Version>
            <ebl:SetExpressCheckoutRequestDetails>
                <ebl:ReturnURL>http://127.0.0.1:8888/ReturnURL</ebl:ReturnURL>
                <ebl:CancelURL>http://127.0.0.1:8888/CancelURL</ebl:CancelURL>
                <ebl:BillingAgreementDetails>
                    <ebl:BillingType>RecurringPayments</ebl:BillingType>
                    <ebl:BillingAgreementDescription>Buyer is billed at &quot;USD1.00&quot; per month
                    </ebl:BillingAgreementDescription>
                </ebl:BillingAgreementDetails>
                <ebl:PaymentDetails>
                    <ebl:OrderTotal currencyID="USD">1.00</ebl:OrderTotal>
                    <ebl:ItemTotal currencyID="USD">1</ebl:ItemTotal>
                    <ebl:ButtonSource>PayPal_SDK</ebl:ButtonSource>
                    <ebl:NotifyURL>/NotifyURL</ebl:NotifyURL>
                    <ebl:PaymentAction>Sale</ebl:PaymentAction>
                </ebl:PaymentDetails>
            </ebl:SetExpressCheckoutRequestDetails>
        </ns:SetExpressCheckoutRequest>
    </ns:SetExpressCheckoutReq>
</soapenv:Body>

这是回复

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes"
                   xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"
                   xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
                   xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ed="urn:ebay:apis:EnhancedDataTypes"
                   xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
    <SOAP-ENV:Header>
        <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"></Security>
        <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
            <Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">
                <Username xsi:type="xs:string"></Username>
                <Password xsi:type="xs:string"></Password>
                <Signature xsi:type="xs:string"></Signature>
                <Subject xsi:type="xs:string"></Subject>
            </Credentials>
        </RequesterCredentials>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body id="_0">
        <SetExpressCheckoutResponse xmlns="urn:ebay:api:PayPalAPI">
            <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2014-04-05T22:23:40Z</Timestamp>
            <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>
            <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">6c19207a14fd</CorrelationID>
            <Version xmlns="urn:ebay:apis:eBLBaseComponents">109.0</Version>
            <Build xmlns="urn:ebay:apis:eBLBaseComponents">10463669</Build>
            <Token xsi:type="ebl:ExpressCheckoutTokenType">EC-1X212344K9178491M</Token>
        </SetExpressCheckoutResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

在CreateRecurringPaymentsProfile请求中

<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>XXX</ebl:Username>
                <ebl:Password>XXX</ebl:Password>
                <ebl:Signature>XXX</ebl:Signature>
            </ebl:Credentials>
        </ns:RequesterCredentials>
    </soapenv:Header>
    <soapenv:Body>
        <ns:CreateRecurringPaymentsProfileReq>
            <ns:CreateRecurringPaymentsProfileRequest>
                <ebl:Version>109.0</ebl:Version>
                <ebl:CreateRecurringPaymentsProfileRequestDetails>
                    <ebl:Token>EC-1X212344K9178491M</ebl:Token>
                    <ebl:RecurringPaymentsProfileDetails>
                        <ebl:BillingStartDate>2014-04-06T13:21:36Z</ebl:BillingStartDate>
                    </ebl:RecurringPaymentsProfileDetails>
                    <ebl:ScheduleDetails>
                        <ebl:Description>Buyer is billed at &quot;USD1.00&quot; per month</ebl:Description>
                        <ebl:PaymentPeriod>
                            <ebl:BillingPeriod>Month</ebl:BillingPeriod>
                            <ebl:BillingFrequency>12</ebl:BillingFrequency>
                            <ebl:Amount currencyID="USD">1.00</ebl:Amount>
                        </ebl:PaymentPeriod>
                    </ebl:ScheduleDetails>
                </ebl:CreateRecurringPaymentsProfileRequestDetails>
            </ns:CreateRecurringPaymentsProfileRequest>
        </ns:CreateRecurringPaymentsProfileReq>
    </soapenv:Body>
</soapenv:Envelope> 

回复是“无效令牌”

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes"
                   xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"
                   xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
                   xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ed="urn:ebay:apis:EnhancedDataTypes"
                   xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
    <SOAP-ENV:Header>
        <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"></Security>
        <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
            <Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">
                <Username xsi:type="xs:string"></Username>
                <Password xsi:type="xs:string"></Password>
                <Signature xsi:type="xs:string"></Signature>
                <Subject xsi:type="xs:string"></Subject>
            </Credentials>
        </RequesterCredentials>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body id="_0">
        <CreateRecurringPaymentsProfileResponse xmlns="urn:ebay:api:PayPalAPI">
            <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2014-04-05T22:28:11Z</Timestamp>
            <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Failure</Ack>
            <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">50e773299b36f</CorrelationID>
            <Errors xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:ErrorType">
                <ShortMessage xsi:type="xs:string">Invalid Token</ShortMessage>
                <LongMessage xsi:type="xs:string">The token is invalid</LongMessage>
                <ErrorCode xsi:type="xs:token">11502</ErrorCode>
                <SeverityCode xmlns="urn:ebay:apis:eBLBaseComponents">Error</SeverityCode>
            </Errors>
            <Version xmlns="urn:ebay:apis:eBLBaseComponents">109.0</Version>
            <Build xmlns="urn:ebay:apis:eBLBaseComponents">10433064</Build>
            <CreateRecurringPaymentsProfileResponseDetails xmlns="urn:ebay:apis:eBLBaseComponents"
                                                           xsi:type="ebl:CreateRecurringPaymentsProfileResponseDetailsType">
                <ProfileID xsi:type="xs:string"></ProfileID>
                <TransactionID xsi:type="xs:string"></TransactionID>
            </CreateRecurringPaymentsProfileResponseDetails>
        </CreateRecurringPaymentsProfileResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我确信CreateRecurringPaymentsProfile请求令牌是来自SetExpressCheckout的响应令牌。

2 个答案:

答案 0 :(得分:0)

回答我的问题。

OrderTotal应该是seto到“0”,并且应该在SetExpressCheckout请求中删除ItemTotal。

但“无效令牌错误”不是非常有用的错误消息。

答案 1 :(得分:0)

SetExpressCheckOutResponse包含以下代码后,

Map<String, String> sdkConfig = new HashMap<String, String>();
sdkConfig.put("mode", "sandbox");

sdkConfig.put("mode", "sandbox");
sdkConfig.put("acct1.UserName", apiUsername);
sdkConfig.put("acct1.Password", apiPassword);
sdkConfig.put("acct1.Signature", apiSignature);

SimpleDateFormat formatterR = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:sssz");

CreateRecurringPaymentsProfileReq createRecurringPaymentsProfileReq = new CreateRecurringPaymentsProfileReq();
CreateRecurringPaymentsProfileRequestType createRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType();

RecurringPaymentsProfileDetailsType recurringPaymentsProfileDetails = new RecurringPaymentsProfileDetailsType();
recurringPaymentsProfileDetails.setBillingStartDate(formatterR.format(new Date()));
recurringPaymentsProfileDetails.setSubscriberName("YOUR SUBSCRIBER NAME");

BasicAmountType billingAmount = new BasicAmountType(CurrencyCodeType.USD, "1.00");
//I Take as MONTHLY Recurrence
//So that i set periodType as MONTH, frequency as 1 (for every month) and billing amount here i sent as 1 USD
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(BillingPeriodType.MONTH, Integer.parseInt("1"), billingAmount);
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType("Description about payment", paymentPeriod); //description, paymentPeriod object              
CreateRecurringPaymentsProfileRequestDetailsType createRecurringPaymentsProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType(recurringPaymentsProfileDetails, scheduleDetails);

AddressType addressType = new AddressType();
addressType.setStateOrProvince("STATE");
addressType.setCityName("CITY");
addressType.setCountryName("COUNTRY");

PersonNameType personName = new PersonNameType();
personName.setFirstName("SUBSCRIBER FIRST NAME");
personName.setLastName("SUBSCRIBER LAST NAME");

PayerInfoType payerInfoType = new PayerInfoType();
payerInfoType.setAddress(addressType);
payerInfoType.setPayerName(personName);

                CreditCardDetailsType creditCard = new CreditCardDetailsType();
                //creditCard.setCreditCardType(CreditCardTypeType.VISA);

                // Credit Card Number
                creditCard.setCreditCardNumber("CARD NO");//4442662639546634

                // Credit Card Expiration Month
                creditCard.setExpMonth(12);//Integer.parseInt("12")

                // Credit Card Expiration Year
                creditCard.setExpYear(Integer.parseInt(2016);//Integer.parseInt("2016")
                creditCard.setCVV2("CVV CODE");
                creditCard.setCardOwner(payerInfoType);
                createRecurringPaymentsProfileRequestDetails.setCreditCard(creditCard);

                createRecurringPaymentsProfileRequest
                        .setCreateRecurringPaymentsProfileRequestDetails(createRecurringPaymentsProfileRequestDetails);
                createRecurringPaymentsProfileReq
                        .setCreateRecurringPaymentsProfileRequest(createRecurringPaymentsProfileRequest);

                PayPalAPIInterfaceServiceService service = null;
                try {
                    service = new PayPalAPIInterfaceServiceService(sdkConfig);
                } catch (Exception e) {
                    LOGGER.info("Error Message : " + e.getMessage());
                }
                CreateRecurringPaymentsProfileResponseType createRecurringPaymentsProfileResponse = null;
                try {
                    // ## Making API call
                    // Invoke the appropriate method corresponding to API in service
                    // wrapper object
                     createRecurringPaymentsProfileResponse = service
                            .createRecurringPaymentsProfile(createRecurringPaymentsProfileReq);
                } catch (Exception e) {
                    LOGGER.info("Error Message : " + e.getMessage());
                }

                String ProfileID = "";
                // ## Accessing response parameters
                // You can access the response parameters using getter methods in
                // response object as shown below
                // ### Success values
                if (createRecurringPaymentsProfileResponse.getAck().getValue()
                        .equalsIgnoreCase("success")) {

                    // A unique identifier for future reference to the details of
                    // this recurring payment.
                    ProfileID = createRecurringPaymentsProfileResponse
                            .getCreateRecurringPaymentsProfileResponseDetails()
                            .getProfileID();
                    LOGGER.info("Profile ID:"+ProfileID);
                    //mes = "approved";
                }
                // ### Error Values
                // Access error values from error list using getter methods
                else {
                    List<ErrorType> errorList = createRecurringPaymentsProfileResponse
                            .getErrors();
                    LOGGER.info("API Error Message : "
                            + errorList.get(0).getLongMessage());
                    //mes = "error";
                }

我希望这会对你有所帮助......