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

When charging a token, cardReference is ran through "json_decode" and if not a json string get standard php error. #85

Open
njdubois opened this issue May 30, 2017 · 0 comments

Comments

@njdubois
Copy link

TL;DR:
Charge token,
'cardReference' => json_decode($token),

Got error from omnipay/auth.net code (php didn't throw exception):
"json_decode() expects parameter 1 to be string, array given"

It would be nice if the returned error was a little more appropriate for the cause of the error.
"Card Reference must be this, this or this. You submitted this."

The details:

I am writing code to charge a token through authorize.net. I am storing a previously generated card reference in my database as a json string.

This looks something like this:
{"customerProfileId":"#######","customerPaymentProfileId":"#######"}

When it came time to actually charge it, I decoded it:

    $purchaseDetails = [
        'amount' => $amount,
        'currency' => 'USD',
        'cardReference' => json_decode($token),
    ];

Than actually sending the charge:

    try {
        $responseFromGateway = $gateway->purchase($purchaseDetails)->send();
    } catch (Exception $e) {
        return $this->handleErrorReturn($e->getMessage(),$submitData);
    }

Ignore submit data, it is a master array I build, handleErrorReturn is just a method I can format errors in a more use friendly output, and log advanced details.

The problem is that I would land in the catch, and the message would be:
"json_decode() expects parameter 1 to be string, array given"

It isn't php blowing up, it's code inside omnipay or the auth.net plug in and because I was just recently decoding something it took me a second to realize my code was ok, that I didn't need to decode the token.

It would be nice if the returned error was a little more appropriate for the cause of the error.

"Card Reference must be this, this or this. You submitted this."

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

No branches or pull requests

1 participant