代码之家  ›  专栏  ›  技术社区  ›  Dogoferis

PayPal setExpressCheckout调用因RETURN和CANCEL URL无效而失败

  •  1
  • Dogoferis  · 技术社区  · 13 年前

    我目前正在将PayPal Express Checkout集成到我们的网站中。我们正在使用osCommerce(PHP)的安装和setExpressCheckout的SOAP实现。令人困惑的是,我的快速结账代码在我的本地环境中正常工作。

    然而委托给我们的开发服务器后,Express Checkout的相同代码不再有效。

    下面是我的本地开发环境向PayPal Sandbox端点发起的用于快速结账的成功SOAP请求。

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
      <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI">
        <Credentials xmlns="urn:ebay:apis:eBLBaseComponents">
          <Username>xxxxxxxxxxxxxxxxxxxxxxxxxxx</Username>
          <Password>xxxxxxxxxxxxxxxx</Password>
        </Credentials>
      </RequesterCredentials>
    </soap:Header>
    <soap:Body>
      <SetExpressCheckoutReq xmlns="urn:ebay:api:PayPalAPI">
        <SetExpressCheckoutRequest>
          <Version xmlns="urn:ebay:apis:eBLBaseComponents">98.0</Version>
          <SetExpressCheckoutRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">
            <ReturnURL>http://localhost/checkout_shipping.php?action=express_checkout&amp;site=xxxxx</ReturnURL>
            <CancelURL>http://localhost/checkout_shipping.php?ec_cancel=1&amp;site=xxxxx</CancelURL>
            <ReqConfirmShipping>1</ReqConfirmShipping>
            <NoShipping>0</NoShipping>
            <AddressOverride>0</AddressOverride>
            <LocaleCode>US</LocaleCode>
            <PageStyle></PageStyle>
            <cpp-header-image></cpp-header-image>
            <cpp-header-border-color></cpp-header-border-color>
            <cpp-header-back-color></cpp-header-back-color>
            <cpp-payflow-color></cpp-payflow-color>
            <PaymentAction>Sale</PaymentAction>
            <PaymentDetails>
              <OrderTotal currencyID="USD">6.47</OrderTotal>
              <ItemTotal currencyID="USD">2.48</ItemTotal>
              <ShippingTotal currencyID="USD">3.99</ShippingTotal>
              <HandlingTotal currencyID="USD"></HandlingTotal>
              <TaxTotal currencyID="USD">0</TaxTotal>
              <Custom>Phone: xxxxxxxxxx -- Email: xxxx.xxxxx@gmail.com</Custom>
              <InvoiceID></InvoiceID>
              <NotifyURL></NotifyURL>
              <ButtonSource>PAYPAL_BUTTON_SOURCE</ButtonSource>
              <ShipToAddress>
                <Name></Name>
                <Street1>xxxx Park Forest Circle</Street1>
                <Street2></Street2>
                <CityName>Clermont</CityName> 
                <StateOrProvince>OH</StateOrProvince>
                <PostalCode>xxx03</PostalCode>
                <Country>US</Country>
              </ShipToAddress>
              <PaymentDetailsItem><Name>Product XYZ</Name><Amount currencyID="USD">2.48</Amount><Number>-</Number><Quantity>1</Quantity></PaymentDetailsItem>
            </PaymentDetails>
          </SetExpressCheckoutRequestDetails>
        </SetExpressCheckoutRequest> 
      </SetExpressCheckoutReq>
    </soap:Body>
    </soap:Envelope>
    

    下面是我从API端点检索到的响应

    <?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">2013-03-27T18:46:35Z</Timestamp>
                <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>
                <CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">cca293672cf33</CorrelationID>
                <Version xmlns="urn:ebay:apis:eBLBaseComponents">98.0</Version>
                <Build xmlns="urn:ebay:apis:eBLBaseComponents">5551055</Build>
                <Token xsi:type="ebl:ExpressCheckoutTokenType">EC-2CM343011B950025M</Token>
            </SetExpressCheckoutResponse>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    然而,如果我从DEV服务器发起相同类型的事务;这将导致失败。在下面查找从我们的开发服务器启动的请求的var_dump()

    Array ( 
        [PAYPAL_ORDER_TOTAL] => 7.84 
        [PAYPAL_ORDER_DESCRIPTION] => Order placed on April 2, 2013, 9:30 am by xxxx xxxxx (ID: xxxxx)  
        [PAYPAL_CUSTOM] => Phone: xxxxxxxxxx -- Email: xxxx.xxxxx@gmail.com 
        [PAYPAL_SHIPPING_TOTAL] => 0 
        [PAYPAL_HANDLING_TOTAL] => 
        [PAYPAL_TAX_TOTAL] => 0 
        [PAYPAL_ITEM_TOTAL] => 7.84 
        [PAYMENT_DETAILS_ITEM] => Product XYZ 
        [PAYPAL_SHIPPING_NAME] => 
        [PAYPAL_SHIPPING_ADDRESS1] => xxxx Rainbow Springs Ct 
        [PAYPAL_SHIPPING_ADDRESS2] =>  
        [PAYPAL_SHIPPING_CITY] => Louisville 
        [PAYPAL_SHIPPING_STATE] => KY 
        [PAYPAL_SHIPPING_ZIP] => 40213 
        [PAYPAL_SHIPPING_COUNTRY] => US 
        [PAYPAL_NOTIFY_URL] => 
        [PAYPAL_INVOICE_ID] => 
        [PAYPAL_PAGE_STYLE] => 
        [PAYPAL_CPP_HEADER_IMAGE] => 
        [PAYPAL_CPP_HEADER_BORDER_COLOR] => 
        [PAYPAL_CPP_HEADER_BACK_COLOR] => 
        [PAYPAL_CPP_PAYFLOW_COLOR] => 
        [PAYPAL_RETURN_URL] => http://wpp_mod.testosc.storename.com/checkout_shipping.php?action=express_checkout&site=xxxxx 
        [PAYPAL_CANCEL_URL] => http://wpp_mod.testosc.storename.com/checkout_shipping.php?ec_cancel=1&site=xxxxx        
        [PAYPAL_REQUIRE_CONFIRM_SHIPPING] => 1 
        [PAYPAL_LOCALE_CODE] => US 
        [PAYPAL_NO_SHIPPING] => 0 
        [PAYPAL_ADDRESS_OVERRIDE] => 0 
    ) 
    

    此请求会产生以下响应(同样是返回的var_dump()):

    Array (
        [Security] => 
        [RequesterCredentials] => 
            Array ( [0] => 
                Array ( 
                    [Credentials] => 
                        Array ( [0] => 
                            Array ( 
                                [Username] => 
                                [Password] => 
                                [Signature] => 
                                [Subject] => 
                            ) 
                        ) 
                    ) 
                ) 
        [SetExpressCheckoutResponse] => 
            Array ( [0] => 
                Array ( 
                    [Timestamp] => 2013-04-02T14:30:46Z 
                    [Ack] => Failure 
                    [CorrelationID] => 44f876829f4cb 
                    [Errors] => 
                        Array ( [0] => Array ( 
                                [ShortMessage] => Transaction refused because of an invalid argument. See additional error messages for details. 
                                [LongMessage] => ReturnURL is invalid. 
                                [ErrorCode] => 10471 
                                [SeverityCode] => Error ) 
                            [1] => Array ( 
                                [ShortMessage] => Transaction refused because of an invalid argument. See additional error messages for details. 
                                [LongMessage] => CancelURL is invalid. 
                                [ErrorCode] => 10472 
                                [SeverityCode] => Error ) 
                        ) 
                    [Version] => 98.0 
                    [Build] => 5613839 
                ) 
            ) 
    )
    

    检查PayPal API文档后 setExpressCheckout 就API端点在有效URL中查找的内容而言,我找不到任何特定的指导原则。

    我也检查过 SO1 SO2 但没有看到任何与我的特定问题有关的东西。

    如果有人知道RETURN和CANCEL URL可能有什么问题,或者更详细地解释setExpressCheckout API的正确格式的URL,这将非常有帮助。

    1 回复  |  直到 9 年前
        1
  •  3
  •   Dogoferis    13 年前

    PayPal API端点似乎不喜欢域/url中的下划线,因此:

    http://localhost/checkout_shipping.php?action=express_checkout&amp;site=xxxxx
    

    有效,但这个

    http://wpp_mod.testosc.storename.com/checkout_shipping.php?action=express_checkout&site=xxxxx
    

    不是;因为我们在开发服务器的域名中有一个下划线。这很不方便,但可以纠正。

    推荐文章