sdk-php
sdk-php copied to clipboard
Error for float amount
Hello,
I'm using this lib version 2.0.0. When I set amount of transaction as float (as referred here: https://github.com/AuthorizeNet/sdk-php/blob/master/lib/net/authorize/api/contract/v1/TransactionRequestType.php#L231) $transactionRequestType->setAmount( (float)$this->amount );
I receive error from authnet (sorry for some reason not formatted even with code markdown)
$request->jsonSerialize()
array (size=2)
'merchantAuthentication' =>
object(net\authorize\api\contract\v1\MerchantAuthenticationType)[628]
private 'name' => string '*' (length=12)
private 'transactionKey' => string '*' (length=16)
private 'sessionToken' => null
private 'password' => null
private 'impersonationAuthentication' => null
private 'fingerPrint' => null
private 'clientKey' => null
private 'accessToken' => null
private 'mobileDeviceId' => null
'transactionRequest' =>
object(net\authorize\api\contract\v1\TransactionRequestType)[642]
private 'transactionType' => string 'authCaptureTransaction' (length=22)
private 'amount' => float 13.82
private 'currencyCode' => string 'USD' (length=3)
private 'payment' =>
object(net\authorize\api\contract\v1\PaymentType)[639]
private 'creditCard' =>
object(net\authorize\api\contract\v1\CreditCardType)[178]
...
private 'bankAccount' => null
private 'trackData' => null
private 'encryptedTrackData' => null
private 'payPal' => null
private 'opaqueData' => null
private 'emv' => null
private 'dataSource' => null
private 'profile' => null
private 'solution' => null
private 'callId' => null
private 'terminalNumber' => null
private 'authCode' => null
private 'refTransId' => string '9526 067a94af816d30' (length=19)
private 'splitTenderId' => null
private 'order' =>
object(net\authorize\api\contract\v1\OrderType)[183]
private 'invoiceNumber' => string '2140868-HPE' (length=11)
private 'description' => string '2140868-HPE' (length=11)
private 'discountAmount' => null
private 'taxIsAfterDiscount' => null
private 'totalTaxTypeCode' => null
private 'purchaserVATRegistrationNumber' => null
private 'merchantVATRegistrationNumber' => null
private 'vatInvoiceReferenceNumber' => null
private 'purchaserCode' => null
private 'summaryCommodityCode' => null
private 'purchaseOrderDateUTC' => null
private 'supplierOrderReference' => null
private 'authorizedContactName' => null
private 'cardAcceptorRefNumber' => null
private 'amexDataTAA1' => null
private 'amexDataTAA2' => null
private 'amexDataTAA3' => null
private 'amexDataTAA4' => null
private 'lineItems' => null
private 'tax' => null
private 'duty' => null
private 'shipping' => null
private 'taxExempt' => null
private 'poNumber' => null
private 'customer' => null
private 'billTo' =>
object(net\authorize\api\contract\v1\CustomerAddressType)[641]
private 'phoneNumber' => string '*' (length=10)
private 'faxNumber' => null
private 'email' => string '*' (length=20)
private 'firstName' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Egor' (length=4)
private 'lastName' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Druzhinin' (length=9)
private 'company' (net\authorize\api\contract\v1\NameAndAddressType) => string '' (length=0)
private 'address' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Mokrushina St. 5/1' (length=18)
private 'city' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Tomsk' (length=5)
private 'state' (net\authorize\api\contract\v1\NameAndAddressType) => null
private 'zip' (net\authorize\api\contract\v1\NameAndAddressType) => string '634045' (length=6)
private 'country' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Russian Federation' (length=18)
private 'shipTo' => null
private 'customerIP' => null
private 'cardholderAuthentication' => null
private 'retail' => null
private 'employeeId' => null
private 'transactionSettings' => null
private 'userFields' => null
private 'surcharge' => null
private 'merchantDescriptor' => null
private 'subMerchant' => null
private 'tip' => null
private 'processingOptions' => null
private 'subsequentAuthInformation' => null
private 'otherTax' => null
private 'shipFrom' => null
$response->jsonSerialize()
Array ( [messages] => net\authorize\api\contract\v1\MessagesType Object ( [resultCode:net\authorize\api\contract\v1\MessagesType:private] => Error [message:net\authorize\api\contract\v1\MessagesType:private] => Array ( [0] => net\authorize\api\contract\v1\MessagesType\MessageAType Object ( [code:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => E00027 [text:net\authorize\api\contract\v1\MessagesType\MessageAType:private] => The transaction was unsuccessful. ) ) ) )
$response->getTransactionResponse()->getErrors()
array (size=1)
0 =>
object(net\authorize\api\contract\v1\TransactionResponseType\ErrorsAType\ErrorAType)[691]
private 'errorCode' => string '5' (length=1)
private 'errorText' => string 'A valid amount is required.' (length=27)
At the same time if trying to send the same transaction with amount formatted as string, that works:
$request->jsonSerialize()
array (size=2)
'merchantAuthentication' =>
object(net\authorize\api\contract\v1\MerchantAuthenticationType)[628]
private 'name' => string '*' (length=12)
private 'transactionKey' => string '*' (length=16)
private 'sessionToken' => null
private 'password' => null
private 'impersonationAuthentication' => null
private 'fingerPrint' => null
private 'clientKey' => null
private 'accessToken' => null
private 'mobileDeviceId' => null
'transactionRequest' =>
object(net\authorize\api\contract\v1\TransactionRequestType)[642]
private 'transactionType' => string 'authCaptureTransaction' (length=22)
private 'amount' => string '13.82' (length=5)
private 'currencyCode' => string 'USD' (length=3)
private 'payment' =>
object(net\authorize\api\contract\v1\PaymentType)[639]
private 'creditCard' =>
object(net\authorize\api\contract\v1\CreditCardType)[178]
...
private 'bankAccount' => null
private 'trackData' => null
private 'encryptedTrackData' => null
private 'payPal' => null
private 'opaqueData' => null
private 'emv' => null
private 'dataSource' => null
private 'profile' => null
private 'solution' => null
private 'callId' => null
private 'terminalNumber' => null
private 'authCode' => null
private 'refTransId' => string '9532 6332c4197c0be4' (length=19)
private 'splitTenderId' => null
private 'order' =>
object(net\authorize\api\contract\v1\OrderType)[183]
private 'invoiceNumber' => string '2140869-HPE' (length=11)
private 'description' => string '2140869-HPE' (length=11)
private 'discountAmount' => null
private 'taxIsAfterDiscount' => null
private 'totalTaxTypeCode' => null
private 'purchaserVATRegistrationNumber' => null
private 'merchantVATRegistrationNumber' => null
private 'vatInvoiceReferenceNumber' => null
private 'purchaserCode' => null
private 'summaryCommodityCode' => null
private 'purchaseOrderDateUTC' => null
private 'supplierOrderReference' => null
private 'authorizedContactName' => null
private 'cardAcceptorRefNumber' => null
private 'amexDataTAA1' => null
private 'amexDataTAA2' => null
private 'amexDataTAA3' => null
private 'amexDataTAA4' => null
private 'lineItems' => null
private 'tax' => null
private 'duty' => null
private 'shipping' => null
private 'taxExempt' => null
private 'poNumber' => null
private 'customer' => null
private 'billTo' =>
object(net\authorize\api\contract\v1\CustomerAddressType)[641]
private 'phoneNumber' => string '*' (length=10)
private 'faxNumber' => null
private 'email' => string '*' (length=20)
private 'firstName' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Egor' (length=4)
private 'lastName' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Druzhinin' (length=9)
private 'company' (net\authorize\api\contract\v1\NameAndAddressType) => string '' (length=0)
private 'address' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Mokrushina St. 5/1' (length=18)
private 'city' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Tomsk' (length=5)
private 'state' (net\authorize\api\contract\v1\NameAndAddressType) => null
private 'zip' (net\authorize\api\contract\v1\NameAndAddressType) => string '634045' (length=6)
private 'country' (net\authorize\api\contract\v1\NameAndAddressType) => string 'Russian Federation' (length=18)
private 'shipTo' => null
private 'customerIP' => null
private 'cardholderAuthentication' => null
private 'retail' => null
private 'employeeId' => null
private 'transactionSettings' => null
private 'userFields' => null
private 'surcharge' => null
private 'merchantDescriptor' => null
private 'subMerchant' => null
private 'tip' => null
private 'processingOptions' => null
private 'subsequentAuthInformation' => null
private 'otherTax' => null
private 'shipFrom' => null
$response->jsonSerialize()
array (size=1)
'messages' =>
object(net\authorize\api\contract\v1\MessagesType)[689]
private 'resultCode' => string 'Ok' (length=2)
private 'message' =>
array (size=1)
0 =>
object(net\authorize\api\contract\v1\MessagesType\MessageAType)[694]
...
Can you guys please comment on this? I don't think it makes sense to format float as string. Float values worked for us in 1.9.*.
Hi,
Thanks for sharing this, so as you are doing explicit typecast this is not working. We will look into this why the SDK is treating it as float value. in 2.0.0 there has been changes to SDK serialization which might be causing this issue, will keep you posted.
Meanwhile, can you please try to store in a temp variable after typecast and then send it ? what happens in that case ?
We are getting the same A valid amount is required.
error message, however, we are using v1.9.9. I also opened up an issue #366. Are these issues related?
I'm also getting this error. it's really weird issue
i use
- $amount = $myobject->price; << returned (float) 65.92 result: A valid amount is required
- $amount = (float) 65.92; << also returned (float) 65.92 same as above, result: success
- $amount = (string) $myobject->price; << returned String "65.92" result: success
so I have to return my amount as a string to get it works.