1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67:
<?php
namespace Omnipay\Dummy\Message;
use Omnipay\Common\Message\AbstractRequest;
/**
* Dummy Authorize Request
*
* ### Example
*
* <code>
* // Create a gateway for the Dummy Gateway
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('Dummy');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'testMode' => true, // Doesn't really matter what you use here.
* ));
*
* // Create a credit card object
* // This card can be used for testing.
* $card = new CreditCard(array(
* 'firstName' => 'Example',
* 'lastName' => 'Customer',
* 'number' => '4242424242424242',
* 'expiryMonth' => '01',
* 'expiryYear' => '2020',
* 'cvv' => '123',
* ));
*
* // Do an authorize transaction on the gateway
* $transaction = $gateway->authorize(array(
* 'amount' => '10.00',
* 'currency' => 'AUD',
* 'card' => $card,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "Authorize transaction was successful!\n";
* $sale_id = $response->getTransactionReference();
* echo "Transaction reference = " . $sale_id . "\n";
* }
* </code>
*/
class AuthorizeRequest extends AbstractRequest
{
public function getData()
{
$this->validate('amount', 'card');
$this->getCard()->validate();
return array('amount' => $this->getAmount());
}
public function sendData($data)
{
$data['reference'] = uniqid();
$data['success'] = 0 === substr($this->getCard()->getNumber(), -1, 1) % 2;
$data['message'] = $data['success'] ? 'Success' : 'Failure';
return $this->response = new Response($this, $data);
}
}