我在尝试使用SagePay Server时遇到以下错误(从打印出来的响应中):
["data":protected]=>array(3) {
["VPSProtocol"]=>
string(4) "2.23"
["Status"]=>
string(7) "INVALID"
["StatusDetail"]=>
string(107) "The data in the BillingCountry field you supplied is an invalid length. Must be an ISO 3166-1 country code."
}
但我传递了价值" GB"作为billingCountry是正确的(SagePay期望billingCountry是按字母顺序排列的,最多2个字符)
["card"]=>
object(Omnipay\Common\CreditCard)#46 (1) {
["parameters":protected]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#48 (1) {
["parameters":protected]=>
array(11) {
["email"]=>
string(17) "test@test.com"
["billingFirstName"]=>
string(3) "Joe"
["shippingFirstName"]=>
string(3) "Joe"
["billingLastName"]=>
string(6) "Bloggs"
["shippingLastName"]=>
string(6) "Bloggs"
["billingAddress1"]=>
string(9) "Address 1"
["billingAddress2"]=>
string(9) "Address 2"
["billingCity"]=>
string(4) "City"
["billingPostcode"]=>
string(7) "AB1 1BA"
["billingCountry"]=>
string(2) "GB"
["billingPhone"]=>
string(13) "01234 567 890"
}
}
这是我的代码:
$response = $this->gateway->Purchase(array(
'description'=> 'Online order',
'currency'=> 'GBP',
'transactionId'=> mt_rand(99, 9999),
'transactionReference' => 'test order',
'amount'=> '1.00',
'returnUrl' => 'http://www.test.com/returnURL/',
'cancelUrl' => 'http://www.test.com/cancelURL/',
'card' => array(
'email' => 'test@test.com',
'clientIp' => '123.123.123.123',
'firstName' => 'Joe',
'LastName' => 'Bloggs',
'billingAddress1' => 'Address 1',
'billingAddress2' => 'Address 2',
'billingCity' => 'City',
'billingPostcode' => 'AB1 1BA',
'billingCountry' => 'GB',
'billingPhone' => '01234 567 890'
)))->send();
我无法解决这个问题,因为它看起来都很正确。我想我有点疯了!我错过了完全明显的吗?
更新于28.07.2014: 我一直在尝试各种各样的事情,包括以不同的格式发送数据:
$formInputData = array(
'firstName' => 'Joe',
'lastName' => 'Bloggs',
'billingAddress1' => '88',
'billingAddress2' => 'Address 2',
'billingCity' => 'City',
'billingPostcode' => '412',
'billingCountry' => 'GB',
'billingPhone' => '01234 567 890',
'email' => 'test@test.com',
'clientIp' => '123.123.123.123'
);
$card = new CreditCard($formInputData);
$transactionID = mt_rand(99, 9999);
$response = $this->gateway->purchase(['amount' => '1.00', 'returnUrl' => 'http://www.example.com/return/', 'transactionId'=> $transactionID, 'description'=> 'Online order', 'transactionReference' => 'test order', 'currency'=> 'GBP', 'card' => $card])->send();
并没有任何区别。
我还尝试向SagePay Direct和CardSave发送相同的数据(但在卡参数中添加了测试信用卡详细信息)。
使用SagePay Direct,我得到" POST"中缺少BillingCountry字段。
使用CardSave,交易成功完成,但我注意到国家/地区有" N / A"当我查看我的CardSave中的交易历史时。
答案 0 :(得分:1)
当前版本的omnipay / sagepay错误地将美国州设置为非美国帐单邮寄地址。
如果地址在美国境外,则会为SagePay拒绝的州传递NULL。不幸的是,SagePay的错误消息通常是指相邻字段而不是实际错误。所以它抱怨BillingCountry没有被设置,因为它实际上意味着状态未被设置。
Git存储库中有一个针对此错误的修复程序,但它不在主要版本中,因此Composer错过了它。
在此期间,您只需手动将状态设置为空字符串$data['card']['state'] = ''
。
答案 1 :(得分:0)
这可能是区分大小写的问题吗?是否将其更改为" BillingCountry"有什么不同吗?
答案 2 :(得分:0)
firstName和lastName字段 - 它们应该是:
我去年写的网关包中总结了所有字段的属性:
https://github.com/academe/SagePay/blob/master/src/Academe/SagePay/Metadata/Transaction.php
这包括字段名称,长度,强制状态,允许的字符以及使用字段的事务类型。这些详细信息很难从文档中提取,而且很多都没有记录,并且已经通过试验和错误。
编辑:如果Omnipay翻译字段名称,这可能是一个愚蠢的答案,所以请随意忽略它。我的头是在SagePay,而不是Omnipay。
答案 3 :(得分:0)
为响应Jason的评论/答案,Omnipay处理多个支付网关,因此将特定网关所期望的字段转换为正确的字段名称。在SagePay的情况下,这是:
protected function getBaseAuthorizeData()
{
$this->validate('amount', 'card', 'transactionId');
$card = $this->getCard();
$data = $this->getBaseData();
$data['Description'] = $this->getDescription();
$data['Amount'] = $this->getAmount();
$data['Currency'] = $this->getCurrency();
$data['VendorTxCode'] = $this->getTransactionId();
$data['ClientIPAddress'] = $this->getClientIp();
$data['ApplyAVSCV2'] = $this->getApplyAVSCV2() ?: 0;
$data['Apply3DSecure'] = $this->getApply3DSecure() ?: 0;
// billing details
$data['BillingFirstnames'] = $card->getFirstName();
$data['BillingSurname'] = $card->getLastName();
$data['BillingAddress1'] = $card->getBillingAddress1();
$data['BillingAddress2'] = $card->getBillingAddress2();
$data['BillingCity'] = $card->getBillingCity();
$data['BillingPostCode'] = $card->getBillingPostcode();
$data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : null;
$data['BillingCountry'] = $card->getBillingCountry();
$data['BillingPhone'] = $card->getBillingPhone();
// shipping details
$data['DeliveryFirstnames'] = $card->getFirstName();
$data['DeliverySurname'] = $card->getLastName();
$data['DeliveryAddress1'] = $card->getShippingAddress1();
$data['DeliveryAddress2'] = $card->getShippingAddress2();
$data['DeliveryCity'] = $card->getShippingCity();
$data['DeliveryPostCode'] = $card->getShippingPostcode();
$data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : null;
$data['DeliveryCountry'] = $card->getShippingCountry();
$data['DeliveryPhone'] = $card->getShippingPhone();
$data['CustomerEMail'] = $card->getEmail();
return $data;
}
答案 4 :(得分:0)
由于此错误已得到修复,我也遇到了错误。然而,上面提到的错误现在已得到修复。
在我的情况下,问题源于使用" DeliveryXXXX"而不是" ShippingXXXX"。一旦我将所有送货实例更改为送货,我就停止收到错误。