使用php curl将XML数据发送到paylease网关

时间:2016-05-20 05:48:39

标签: php xml curl

我将xml数据发送到paylease支付网关,并显示以下错误:

Array
(
    [Credentials] => Array
        (
            [GatewayId] => sssssssssssss
            [Username] => ssssssssssssss
        )

    [Mode] => Array
        (
        )

    [Errors] => Array
        (
            [Error] => Array
                (
                    [0] => Array
                        (
                            [Code] => 146
                            [Status] => Error
                            [Message] => GatewayId not found.
                        )

                    [1] => Array
                        (
                            [Code] => 155
                            [Status] => Error
                            [Message] => User failed to be authenticated.  GatewayId and username don't match.
                        )

                    [2] => Array
                        (
                            [Code] => 156
                            [Status] => Error
                            [Message] => User failed to be authenticated.  Username and password don't match.
                        )

                )

        )

)

我使用curl将xml请求发送到支付网关。请帮我发送请求到支付网关。我使用下面给出的代码:

 - $xml = "<?xml version='1.0' encoding='UTF-8'?>
                <PayLeaseGatewayRequest>
                <Credentials>
                <GatewayId>####</GatewayId>
                <Username>#####</Username>
                <Password>####</Password>
                </Credentials>
                <Mode>Test</Mode>
                <Transactions>
                <Transaction>
                <TransactionAction>CCPayment</TransactionAction>
                <PaymentReferenceId>CC12345</PaymentReferenceId>
                <PaymentTraceId>1</PaymentTraceId>
                <PayerReferenceId>395</PayerReferenceId>
                <PayeeId>129</PayeeId>
                <PayerFirstName>John</PayerFirstName>
                <PayerLastName>Smith</PayerLastName>
                <CreditCardType>Visa</CreditCardType>
                <CreditCardNumber>4444444444444448</CreditCardNumber>
                <CreditCardExpMonth>05</CreditCardExpMonth>
                <CreditCardExpYear>19</CreditCardExpYear>
                <CreditCardCvv2>123</CreditCardCvv2>
                <BillingFirstName>John</BillingFirstName>
                <BillingLastName>Smith</BillingLastName>
                <BillingStreetAddress>123 PayLease Street</BillingStreetAddress>
                <BillingCity>San Diego</BillingCity>
                <BillingState>CA</BillingState>
                <BillingCountry>US</BillingCountry>
                <BillingZip>92123</BillingZip>
                <TotalAmount>1000.00</TotalAmount>
                <FeeAmount></FeeAmount> 
                <Message></Message > 
                <IncurFee>No</IncurFee>
                <SaveAccount>Yes</SaveAccount>
                </Transaction>
                </Transactions>
                </PayLeaseGatewayRequest>";


                $url = "https://www.paylease.com/gapi/request.php";

                //setting the curl parameters.
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
                // Following line is compulsary to add as it is:
                    curl_setopt($ch, CURLOPT_POSTFIELDS,"xmlRequest=" . $xml );
                    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
                $data = curl_exec($ch);
                curl_close($ch);

                //convert the XML result into array
                $array_data = json_decode(json_encode(simplexml_load_string($data)), true);
                echo "<pre>";


            print_r($array_data);

0 个答案:

没有答案