thephpleague / omnipay-eway

eWay driver for the Omnipay PHP payment processing library
MIT License
13 stars 17 forks source link

CreateCard isSuccessful() does not work properly. #13

Closed benileo closed 8 years ago

benileo commented 8 years ago
$response = $this->gateway->createCard(['card' => $creditCard])->send();
if ($response->isSuccessful()) // This always fails

See https://go.eway.io/s/question/0D5w000001jr3DjCAI?language=en_US

Perhaps check the response code instead for createCard? Instead of:

public function isSuccessful()
{
    return isset($this->data['TransactionStatus']) && $this->data['TransactionStatus'];
}

I had to implement my own isSuccessful() for this particular gateway (which doesn't seem right)

public function isSuccessful(\Omnipay\Common\Message\AbstractResponse $response)
{
        if ($response->getRequest() instanceof \Omnipay\Eway\Message\RapidDirectCreateCardRequest) {
            return $response->getCode() == 'A2000';
        }

        return parent::isSuccessful($response);
}
incarnate commented 8 years ago

Good catch Ben, interestingly the test for this function expects false:

$this->assertFalse($response->isSuccessful());

The gateway logic is that since no transaction took place, TransactionStatus is false.

However I agree this means that isSuccessful here gives unexpected results. The solution may be to create a RapidDirectCreateCardResponse class which overrides isSuccessful with criteria along the lines of what you're using. Or I'm open to other ideas!

delatbabel commented 8 years ago

The solution may be to create a RapidDirectCreateCardResponse class which overrides isSuccessful with criteria along the lines of what you're using.

That sounds the most logical suggestion to me. If someone submits a PR then I will merge it.