无法让lineitems在Authorized.net xml createTransactionRequest中工作

时间:2013-02-04 21:16:31

标签: php authorize.net

我试图从mysql表中获取信息并将其插入到createTransactionRequest数组中以显示电子邮件中的lineitems。当我这样做并在页面上回显它看起来应该但它会一直给我一个错误。如果我删除数组($ lineitem)我创建它会很好。我觉得我插入了这个错误,或者只是不可能按照我想要的方式这样做。希望有更多经验的人可以帮助我解决这个问题。

我像这样创建数组。

while($r = mysql_fetch_array($cartitems)) {
$lineitem[] = array('itemId' => ''.$r['itemid'].'','name' => ''.$r['productname'].'','description' => ''.$r['productdescription'].'','quantity' => '1','unitPrice' => ''.$price.'');
}

然后我将它插入这个数组..

$xml->createTransactionRequest(array(
'refId' => rand(1000000, 100000000),
'transactionRequest' => array(
'transactionType' => 'authCaptureTransaction',
'amount' => 45.00,
'payment' => array(
'creditCard' => array(
    'cardNumber' => '4111111111111111',
    'expirationDate' => '122015',
    'cardCode' => '123',
),
),
'order' => array(
'invoiceNumber' => '123123',
'description' => 'Purchase from website',
),
'lineItems' => array(
'lineItem' => $lineitem
),
'poNumber' => '123123321',
'customer' => array(
'id' => 123,
'email' => email@website.com,
),
'billTo' => array(
'firstName' => $firstname,
'lastName' => $lastname,
'address' => $address,
'city' => $city,
'state' => $state,
'zip' => $zipcode,
'country' => 'USA',
),
'customerIP' => 12-12-12-1234,
'transactionSettings' => array(
'setting' => array(
    0 => array(
        'settingName' =>'allowPartialAuth',
        'settingValue' => 'false'
                                                ),
    1 => array(
        'settingName' => 'duplicateWindow',
        'settingValue' => '0'
    ),
    2 => array(
        'settingName' => 'emailCustomer',
        'settingValue' => 'true'
    ),
    3 => array(
        'settingName' => 'recurringBilling',
        'settingValue' => 'false'
    ),
    4 => array(
        'settingName' => 'testRequest',
        'settingValue' => 'false'
    )
)
),
),
));

---------------编辑如下,显示来自print ----------------

的输出
Array
(
    [refId] => 90801855
    [transactionRequest] => Array
        (
            [transactionType] => authCaptureTransaction
            [amount] => 31.41
            [payment] => Array
                (
                    [creditCard] => Array
                        (
                            [cardNumber] => 4111111111111111
                            [expirationDate] => 042012
                            [cardCode] => 123
                        )

                )

            [order] => Array
                (
                    [invoiceNumber] => 1360116011
                    [description] => Purchase from website
                )

            [lineItems] => Array
                (
                    [lineItem] => Array
                        (
                            [0] => Array
                                (
                                    [itemId] => 1
                                    [name] => item one title
                                    [description] => item one description
                                    [quantity] => 1
                                    [unitPrice] => 19.90
                                )

                            [1] => Array
                                (
                                    [itemId] => 4
                                    [name] => item 4 title
                                    [description] => item 4 description
--
                                    [quantity] => 1
                                    [unitPrice] => 15.00
                                )

                        )

                )

            [poNumber] => 22
            [customer] => Array
                (
                    [id] => 2
                    [email] => email@website.com
                )

            [billTo] => Array
                (
                    [firstName] => john
                    [lastName] => smith
                    [address] => 132 addy here lane
                    [city] => foxboro
                    [state] => MA
                    [zip] => 01955
                    [country] => USA
                )

            [customerIP] => 12.123.123.123
            [transactionSettings] => Array
                (
                    [setting] => Array
                        (
                            [0] => Array
                                (
                                    [settingName] => allowPartialAuth
                                    [settingValue] => false
                                )

                            [1] => Array
                                (
                                    [settingName] => duplicateWindow
                                    [settingValue] => 0
                                )

                            [2] => Array
                                (
                                    [settingName] => emailCustomer
                                    [settingValue] => true
                                )

                            [3] => Array
                                (
                                    [settingName] => recurringBilling
                                    [settingValue] => false
                                )

                            [4] => Array
                                (
                                    [settingName] => testRequest
                                    [settingValue] => false
                                )

                        )

                )

        )

)

1 个答案:

答案 0 :(得分:0)

我不知道这是好消息还是坏消息。我能够使用您提供的数据使我的两个测试工作。

第一个代码示例使用我的示例代码和您提供的数据。示例代码使用您在上面提供的代码以及我手动添加的订单项。您可以在第三个代码示例中看到请求和响应XML。

虽然我们在这里解决了一些可能有用的提示:

  • 在上面提供的示例数据中,在第二个项目中,我随机看到了几个短划线--。它们在你的代码中吗?或者那只是一个切口&粘贴错误?
  • Authorize.Net并不关心数字值是否在引号中传递,因此将它们放在那里总是一个好主意。