On the sandbox API endpoint i try to refund a previously valid transaction (120053733345) with the following createTransactionRequest array (converted into JSON):
Array
(
[merchantAuthentication] => Array
(
[name] => mytestname
[transactionKey] => mytestkey
)
[refId] => 1041-352205
[transactionRequest] => Array
(
[transactionType] => refundTransaction
[amount] => 29.00
[currencyCode] => CAD
[refTransId] => 120053733345
[payment] => Array
(
[creditCard] => Array
(
[cardNumber] => 5121212121212124
[expirationDate] => 2028-01
)
)
)
)
While the authCaptureTransaction operation works fine, i receive an error with the refundTransaction operation:
The element 'transactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'payment' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'splitTenderId, order, lineItems, tax, duty, shipping, taxExempt, poNumber, customer, billTo, shipTo, customerIP, cardholderAuthentication, retail, employeeId, transactionSettings, userFields, surcharge, merchantDescriptor, subMerchant, tip, processingOptions, subsequentAuthInformation, otherTax, shipFrom, authorizationIndicatorType' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.
I've tried to follow the instruction in https://developer.authorize.net/api/reference/index.html#payment-transactions-refund-a-transaction and Is it possible to refund a transaction in Authorize.Net sandbox account? but with no success.
The real problem is with your refTransId
parameter. It must be after the payment
section.
Array
(
[merchantAuthentication] => Array
(
[name] => mytestname
[transactionKey] => mytestkey
)
[refId] => 1041-352205
[transactionRequest] => Array
(
[transactionType] => refundTransaction
[amount] => 29.00
[currencyCode] => CAD
[payment] => Array
(
[creditCard] => Array
(
[cardNumber] => 5121212121212124
[expirationDate] => 2028-01
)
)
[refTransId] => 120053733345
)
)
Although you are sending your request as JSON, this JSOPN API sits on top of an XML API which was, at one time, the only way to use Authnet's APIs. JSON was added on later and is converted to XML and then validated. This is why you get this error despite this being JSON and not XML.