Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to get the numbers from the accountNumber in the response body #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

aryehischechter
Copy link

If last four numbers of the card aren't present in the card object (because the payment was done with opaqueData), try to get the numbers from the accountNumber in the response body.

This is so that refunds can be done for transactions without a card, like apple pay or when using Accept.js.

This is really to solve digital-pros/commerce-authorize#15

@judgej
Copy link
Member

judgej commented Aug 31, 2020

This gets the last card digits, which is great, but I'm not sure where the expiry date is coming from. I get "199912" every time, regardless of what the actual expiry date is, which looks like it may be the default that Omnipay returns (which seems like a big to me).

I can't see the expiry date in the raw payload either for the AJS response, so maybe it's not needed, or is ignored? Or maybe the XML is not being parsed correctly?

object(SimpleXMLElement)#29 (13) {
  ["responseCode"]=>
  string(1) "1"
  ["authCode"]=>
  string(6) "000000"
  ["avsResultCode"]=>
  string(1) "P"
  ["cvvResultCode"]=>
  object(SimpleXMLElement)#31 (0) {
  }
  ["cavvResultCode"]=>
  object(SimpleXMLElement)#42 (0) {
  }
  ["transId"]=>
  string(1) "0"
  ["refTransID"]=>
  object(SimpleXMLElement)#51 (0) {
  }
  ["transHash"]=>
  object(SimpleXMLElement)#32 (0) {
  }
  ["testRequest"]=>
  string(1) "1"
  ["accountNumber"]=>
  string(8) "XXXX0027"
  ["accountType"]=>
  string(4) "Visa"
  ["messages"]=>
  object(SimpleXMLElement)#48 (1) {
    ["message"]=>
    object(SimpleXMLElement)#44 (2) {
      ["code"]=>
      string(1) "1"
      ["description"]=>
      string(35) "This transaction has been approved."
    }
  }
  ["transHashSha2"]=>
  string(128) "70BADC10C279FD5102EC17DDB18225E46CBD1381C3E06C85976A5727415DA9E6BFAA758ABF15D1B6745D41D18FD355E0AFED8E5E5E7FCD06D34B0216E108EE48"
}

@judgej
Copy link
Member

judgej commented Aug 31, 2020

The raw AJS (using opaque data) rtesponse body:

<?xml version="1.0" encoding="UTF-8"?>
<createTransactionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <refId>313826278</refId>
   <messages>
      <resultCode>Ok</resultCode>
      <message>
         <code>I00001</code>
         <text>Successful.</text>
      </message>
   </messages>
   <transactionResponse>
      <responseCode>1</responseCode>
      <authCode>000000</authCode>
      <avsResultCode>P</avsResultCode>
      <cvvResultCode />
      <cavvResultCode />
      <transId>0</transId>
      <refTransID />
      <transHash />
      <testRequest>1</testRequest>
      <accountNumber>XXXX0027</accountNumber>
      <accountType>Visa</accountType>
      <messages>
         <message>
            <code>1</code>
            <description>This transaction has been approved.</description>
         </message>
      </messages>
      <transHashSha2>70BADC10C279FD5102EC17DDB18225E46CBD1381C3E06C85976A5727415DA9E6BFAA758ABF15D1B6745D41D18FD355E0AFED8E5E5E7FCD06D34B0216E108EE48</transHashSha2>
   </transactionResponse>
</createTransactionResponse>

No expiry dates in there. Does it work for you if you drop the expiry date altogether when the card object does not have it set for the request?

@judgej
Copy link
Member

judgej commented Aug 31, 2020

Looking at this example here: https://developer.authorize.net/api/reference/features/acceptjs.html#Integrating_Accept.js_into_Your_Payment_Form the payment form has names for the expiry date fields. That means although the card number (and CVV) are not captured direct to the merchant site, the month and year are captured directly.

I wonder if the month and year need to be captured with the user accept.js form submission at the same time as the opaque data? I suspect they do. The date would need to be held with the request and make available along with the response, though not actually sent to the Authorize.Net gateway.

@aryehischechter
Copy link
Author

@judgej it's seems you are correct, that the expiration date is still needed even though it is not returned in the response and it is not sent in the request to authorize.net.

The new error I got, after successfully storing and sending the card number is:

"error": {
    "errorCode": "7",
    "errorText": "Credit card expiration date is invalid."
}

For the expiration date I get "121999" which is whats returned for gmdate("mY", gmmktime(0, 0, 0, null, 1, null)), which is the case when there's no expiration date as part of the card.

The solution for regular accept.js usage is probably to store the card details which are provided by accept.js when available.

I'm trying to use Apple Pay, which does not supply the card number or the expiration date.
So right now I don't have a solution.

This pull request can most likely be declined for another solution for storing the card data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants