0

我正在尝试从 mysql 表中提取信息并将其插入 createTransactionRequest 数组以显示电子邮件中的行项。当我这样做并在页面上回显时,它看起来应该是这样,但它一直给我一个错误。如果我删除数组( $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'
    )
)
),
),
));

---------------编辑下面,显示打印输出----------------

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
                                )

                        )

                )

        )

)
4

1 回答 1

0

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

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

在我们解决这个问题时,这里有一些可能有用的提示:

  • 在您上面提供的示例数据中,在第二行项目中,我--随机看到了几个破折号。它们在您的代码中吗?或者这只是一个剪切和粘贴错误?
  • Authorize.Net 并不真正关心数值是否在引号中传递,因此将它们放在那里总是一个好主意。
于 2013-02-06T02:52:26.830 回答