File manager - Edit - /home/opticamezl/www/newok/common.tar
Back
tests/Omnipay/Common/AbstractGatewayTest.php 0000604 00000011320 15174372523 0015212 0 ustar 00 <?php namespace Omnipay\Common; use Mockery as m; use Omnipay\Common\Message\AbstractRequest; use Omnipay\Tests\TestCase; use Symfony\Component\HttpFoundation\ParameterBag; class AbstractGatewayTest extends TestCase { public function setUp() { $this->gateway = m::mock('\Omnipay\Common\AbstractGateway')->makePartial(); $this->gateway->initialize(); } public function testConstruct() { $this->gateway = new AbstractGatewayTest_MockAbstractGateway; $this->assertInstanceOf('\Guzzle\Http\Client', $this->gateway->getProtectedHttpClient()); $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Request', $this->gateway->getProtectedHttpRequest()); $this->assertSame(array(), $this->gateway->getParameters()); } public function testGetShortName() { $this->assertSame('\\'.get_class($this->gateway), $this->gateway->getShortName()); } public function testInitializeDefaults() { $defaults = array( 'currency' => 'AUD', // fixed default type 'username' => array('joe', 'fred'), // enum default type ); $this->gateway->shouldReceive('getDefaultParameters')->once() ->andReturn($defaults); $this->gateway->initialize(); $expected = array( 'currency' => 'AUD', 'username' => 'joe', ); $this->assertSame($expected, $this->gateway->getParameters()); } public function testInitializeParameters() { $this->gateway->shouldReceive('getDefaultParameters')->once() ->andReturn(array('currency' => 'AUD')); $this->gateway->initialize(array( 'currency' => 'USD', 'unknown' => '42', )); $this->assertSame(array('currency' => 'USD'), $this->gateway->getParameters()); } public function testGetDefaultParameters() { $this->assertSame(array(), $this->gateway->getDefaultParameters()); } public function testGetParameters() { $this->gateway->setTestMode(true); $this->assertSame(array('testMode' => true), $this->gateway->getParameters()); } public function testTestMode() { $this->assertSame($this->gateway, $this->gateway->setTestMode(true)); $this->assertSame(true, $this->gateway->getTestMode()); } public function testCurrency() { $this->assertSame($this->gateway, $this->gateway->setCurrency('USD')); $this->assertSame('USD', $this->gateway->getCurrency()); } public function testSupportsAuthorize() { $this->assertFalse($this->gateway->supportsAuthorize()); } public function testSupportsCompleteAuthorize() { $this->assertFalse($this->gateway->supportsCompleteAuthorize()); } public function testSupportsCapture() { $this->assertFalse($this->gateway->supportsCapture()); } public function testSupportsPurchase() { $this->assertFalse($this->gateway->supportsPurchase()); } public function testSupportsCompletePurchase() { $this->assertFalse($this->gateway->supportsCompletePurchase()); } public function testSupportsRefund() { $this->assertFalse($this->gateway->supportsRefund()); } public function testSupportsVoid() { $this->assertFalse($this->gateway->supportsVoid()); } public function testSupportsCreateCard() { $this->assertFalse($this->gateway->supportsCreateCard()); } public function testSupportsDeleteCard() { $this->assertFalse($this->gateway->supportsDeleteCard()); } public function testSupportsUpdateCard() { $this->assertFalse($this->gateway->supportsUpdateCard()); } public function testCreateRequest() { $this->gateway = new AbstractGatewayTest_MockAbstractGateway; $request = $this->gateway->callCreateRequest( '\Omnipay\Common\AbstractGatewayTest_MockAbstractRequest', array('currency' => 'THB') ); $this->assertSame(array('currency' => 'THB'), $request->getParameters()); } } class AbstractGatewayTest_MockAbstractGateway extends AbstractGateway { public function getName() { return 'Mock Gateway Implementation'; } public function getProtectedHttpClient() { return $this->httpClient; } public function getProtectedHttpRequest() { return $this->httpRequest; } public function callCreateRequest($class, array $parameters) { return $this->createRequest($class, $parameters); } } class AbstractGatewayTest_MockAbstractRequest extends AbstractRequest { public function getData() {} public function sendData($data) {} } tests/Omnipay/Common/GatewayFactoryTest.php 0000604 00000005167 15174372523 0015072 0 ustar 00 <?php namespace Omnipay\Common; use Mockery as m; use Omnipay\Tests\TestCase; class GatewayFactoryTest extends TestCase { public static function setUpBeforeClass() { m::mock('alias:Omnipay\\SpareChange\\TestGateway'); } public function setUp() { $this->factory = new GatewayFactory; } public function testReplace() { $gateways = array('Foo'); $this->factory->replace($gateways); $this->assertSame($gateways, $this->factory->all()); } public function testRegister() { $this->factory->register('Bar'); $this->assertSame(array('Bar'), $this->factory->all()); } public function testRegisterExistingGateway() { $this->factory->register('Milky'); $this->factory->register('Bar'); $this->factory->register('Bar'); $this->assertSame(array('Milky', 'Bar'), $this->factory->all()); } public function testFindRegistersAvailableGateways() { $this->factory = m::mock('Omnipay\Common\GatewayFactory[getSupportedGateways]'); $this->factory->shouldReceive('getSupportedGateways')->once() ->andReturn(array('SpareChange_Test')); $gateways = $this->factory->find(); $this->assertContains('SpareChange_Test', $gateways); $this->assertContains('SpareChange_Test', $this->factory->all()); } public function testFindIgnoresUnavailableGateways() { $this->factory = m::mock('Omnipay\Common\GatewayFactory[getSupportedGateways]'); $this->factory->shouldReceive('getSupportedGateways')->once() ->andReturn(array('SpareChange_Gone')); $gateways = $this->factory->find(); $this->assertEmpty($gateways); $this->assertEmpty($this->factory->all()); } public function testCreateShortName() { $gateway = $this->factory->create('SpareChange_Test'); $this->assertInstanceOf('\\Omnipay\\SpareChange\\TestGateway', $gateway); } public function testCreateFullyQualified() { $gateway = $this->factory->create('\\Omnipay\\SpareChange\\TestGateway'); $this->assertInstanceOf('\\Omnipay\\SpareChange\\TestGateway', $gateway); } /** * @expectedException \Omnipay\Common\Exception\RuntimeException * @expectedExceptionMessage Class '\Omnipay\Invalid\Gateway' not found */ public function testCreateInvalid() { $gateway = $this->factory->create('Invalid'); } public function testGetSupportedGateways() { $gateways = $this->factory->getSupportedGateways(); $this->assertContains('Stripe', $gateways); } } tests/Omnipay/Common/Exception/InvalidRequestExceptionTest.php 0000604 00000000447 15174372523 0020711 0 ustar 00 <?php namespace Omnipay\Common\Exception; use Omnipay\Tests\TestCase; class InvalidRequestExceptionTest extends TestCase { public function testConstruct() { $exception = new InvalidRequestException('Oops'); $this->assertSame('Oops', $exception->getMessage()); } } tests/Omnipay/Common/Exception/BadMethodCallExceptionTest.php 0000604 00000000445 15174372523 0020373 0 ustar 00 <?php namespace Omnipay\Common\Exception; use Omnipay\Tests\TestCase; class BadMethodCallExceptionTest extends TestCase { public function testConstruct() { $exception = new BadMethodCallException('Oops'); $this->assertSame('Oops', $exception->getMessage()); } } tests/Omnipay/Common/Exception/InvalidCreditCardExceptionTest.php 0000604 00000000455 15174372523 0021264 0 ustar 00 <?php namespace Omnipay\Common\Exception; use Omnipay\Tests\TestCase; class InvalidCreditCardExceptionTest extends TestCase { public function testConstruct() { $exception = new InvalidCreditCardException('Oops'); $this->assertSame('Oops', $exception->getMessage()); } } tests/Omnipay/Common/Exception/InvalidResponseExceptionTest.php 0000604 00000001020 15174372523 0021043 0 ustar 00 <?php namespace Omnipay\Common\Exception; use Omnipay\Tests\TestCase; class InvalidResponseExceptionTest extends TestCase { public function testConstructWithDefaultMessage() { $exception = new InvalidResponseException(); $this->assertSame('Invalid response from payment gateway', $exception->getMessage()); } public function testConstructWithCustomMessage() { $exception = new InvalidResponseException('Oops'); $this->assertSame('Oops', $exception->getMessage()); } } tests/Omnipay/Common/Exception/RuntimeExceptionTest.php 0000604 00000000431 15174372523 0017366 0 ustar 00 <?php namespace Omnipay\Common\Exception; use Omnipay\Tests\TestCase; class RuntimeExceptionTest extends TestCase { public function testConstruct() { $exception = new RuntimeException('Oops'); $this->assertSame('Oops', $exception->getMessage()); } } tests/Omnipay/Common/ItemBagTest.php 0000604 00000003174 15174372523 0013445 0 ustar 00 <?php namespace Omnipay\Common; use Omnipay\Tests\TestCase; class ItemBagTest extends TestCase { public function setUp() { $this->bag = new ItemBag; } public function testConstruct() { $bag = new ItemBag(array(array('name' => 'Floppy Disk'))); $this->assertCount(1, $bag); } public function testAll() { $items = array(new Item, new Item); $bag = new ItemBag($items); $this->assertSame($items, $bag->all()); } public function testReplace() { $items = array(new Item, new Item); $this->bag->replace($items); $this->assertSame($items, $this->bag->all()); } public function testAddWithItem() { $item = new Item; $item->setName('CD-ROM'); $this->bag->add($item); $contents = $this->bag->all(); $this->assertSame($item, $contents[0]); } public function testAddWithArray() { $item = array('name' => 'CD-ROM'); $this->bag->add($item); $contents = $this->bag->all(); $this->assertInstanceOf('\Omnipay\Common\Item', $contents[0]); $this->assertSame('CD-ROM', $contents[0]->getName()); } public function testGetIterator() { $item = new Item; $item->setName('CD-ROM'); $this->bag->add($item); foreach ($this->bag as $bagItem) { $this->assertSame($item, $bagItem); } } public function testCount() { $this->bag->add(new Item); $this->bag->add(new Item); $this->bag->add(new Item); $this->assertSame(3, count($this->bag)); } } tests/Omnipay/Common/IssuerTest.php 0000604 00000001233 15174372523 0013401 0 ustar 00 <?php namespace Omnipay\Common; use Omnipay\Tests\TestCase; class IssuerTest extends TestCase { public function testConstruct() { $issuer = new Issuer('99', 'Acme Corp'); $this->assertSame('99', $issuer->getId()); $this->assertSame('Acme Corp', $issuer->getName()); $this->assertNull($issuer->getPaymentMethod()); } public function testConstructWithPaymentMethod() { $issuer = new Issuer('99', 'Acme Corp', 'ideal'); $this->assertSame('99', $issuer->getId()); $this->assertSame('Acme Corp', $issuer->getName()); $this->assertSame('ideal', $issuer->getPaymentMethod()); } } tests/Omnipay/Common/CurrencyTest.php 0000604 00000001746 15174372523 0013732 0 ustar 00 <?php namespace Omnipay\Common; use Omnipay\Common\Currency; use Omnipay\Tests\TestCase; class CurrencyTest extends TestCase { public function testFind() { $currency = Currency::find('USD'); $this->assertSame('USD', $currency->getCode()); $this->assertSame('840', $currency->getNumeric()); $this->assertSame(2, $currency->getDecimals()); } public function testFindLowercase() { $currency = Currency::find('usd'); $this->assertSame('USD', $currency->getCode()); $this->assertSame('840', $currency->getNumeric()); $this->assertSame(2, $currency->getDecimals()); } public function testUnknownCurrencyReturnsNull() { $currency = Currency::find('XYZ'); $this->assertNull($currency); } public function testAll() { $currencies = Currency::all(); $this->assertTrue(isset($currencies['USD'])); $this->assertFalse(isset($currencies['XYZ'])); } } tests/Omnipay/Common/PaymentMethodTest.php 0000604 00000000504 15174372523 0014705 0 ustar 00 <?php namespace Omnipay\Common; use Omnipay\Tests\TestCase; class PaymentMethodTest extends TestCase { public function testConstruct() { $method = new PaymentMethod('99', 'Acme Corp'); $this->assertSame('99', $method->getId()); $this->assertSame('Acme Corp', $method->getName()); } } tests/Omnipay/Common/Message/AbstractResponseTest.php 0000604 00000007752 15174372523 0017011 0 ustar 00 <?php namespace Omnipay\Common\Message; use Mockery as m; use Omnipay\Tests\TestCase; class AbstractResponseTest extends TestCase { public function setUp() { $this->response = m::mock('\Omnipay\Common\Message\AbstractResponse')->makePartial(); } public function testConstruct() { $data = array('foo' => 'bar'); $request = $this->getMockRequest(); $this->response = m::mock('\Omnipay\Common\Message\AbstractResponse', array($request, $data))->makePartial(); $this->assertSame($request, $this->response->getRequest()); $this->assertSame($data, $this->response->getData()); } public function testDefaultMethods() { $this->assertFalse($this->response->isRedirect()); $this->assertNull($this->response->getData()); $this->assertNull($this->response->getTransactionReference()); $this->assertNull($this->response->getMessage()); $this->assertNull($this->response->getCode()); } /** * @expectedException \Omnipay\Common\Exception\RuntimeException * @expectedExceptionMessage This response does not support redirection. */ public function testGetRedirectResponseNotImplemented() { $this->response->getRedirectResponse(); } /** * @expectedException \Omnipay\Common\Exception\RuntimeException * @expectedExceptionMessage This response does not support redirection. */ public function testGetRedirectResponseNotSupported() { $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial(); $this->response->shouldReceive('isRedirect')->once()->andReturn(false); $this->response->getRedirectResponse(); } public function testGetRedirectResponseGet() { $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial(); $this->response->shouldReceive('getRedirectMethod')->andReturn('GET'); $httpResponse = $this->response->getRedirectResponse(); $this->assertSame(302, $httpResponse->getStatusCode()); $this->assertSame('https://example.com/redirect?a=1&b=2', $httpResponse->getTargetUrl()); } public function testGetRedirectResponsePost() { $data = array('foo' => 'bar', 'key&"' => '<value>'); $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial(); $this->response->shouldReceive('getRedirectMethod')->andReturn('POST'); $this->response->shouldReceive('getRedirectData')->andReturn($data); $httpResponse = $this->response->getRedirectResponse(); $this->assertSame(200, $httpResponse->getStatusCode()); $this->assertContains('<form action="https://example.com/redirect?a=1&b=2" method="post">', $httpResponse->getContent()); $this->assertContains('<input type="hidden" name="foo" value="bar" />', $httpResponse->getContent()); $this->assertContains('<input type="hidden" name="key&"" value="<value>" />', $httpResponse->getContent()); } /** * @expectedException \Omnipay\Common\Exception\RuntimeException * @expectedExceptionMessage Invalid redirect method "DELETE". */ public function testGetRedirectResponseInvalidMethod() { $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial(); $this->response->shouldReceive('getRedirectMethod')->andReturn('DELETE'); $this->response->getRedirectResponse(); } } class AbstractResponseTest_MockRedirectResponse extends AbstractResponse implements RedirectResponseInterface { public function isSuccessful() { return false; } public function isRedirect() { return true; } public function getRedirectUrl() { return 'https://example.com/redirect?a=1&b=2'; } public function getRedirectMethod() {} public function getRedirectData() {} } tests/Omnipay/Common/Message/AbstractRequestTest.php 0000604 00000026336 15174372523 0016642 0 ustar 00 <?php namespace Omnipay\Common\Message; use Mockery as m; use Omnipay\Common\CreditCard; use Omnipay\Common\ItemBag; use Omnipay\Tests\TestCase; class AbstractRequestTest extends TestCase { public function setUp() { $this->request = m::mock('\Omnipay\Common\Message\AbstractRequest')->makePartial(); $this->request->initialize(); } public function testConstruct() { $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); $this->assertSame(array(), $this->request->getParameters()); } public function testInitializeWithParams() { $this->assertSame($this->request, $this->request->initialize(array('amount' => '1.23'))); $this->assertSame('1.23', $this->request->getAmount()); } /** * @expectedException \Omnipay\Common\Exception\RuntimeException * @expectedExceptionMessage Request cannot be modified after it has been sent! */ public function testInitializeAfterRequestSent() { $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->send(); $this->request->initialize(); } public function testCard() { // no type checking on card parameter $card = new CreditCard; $this->assertSame($this->request, $this->request->setCard($card)); $this->assertSame($card, $this->request->getCard()); } public function testSetCardWithArray() { // passing array should create CreditCard object $this->assertSame($this->request, $this->request->setCard(array('number' => '1234'))); $card = $this->request->getCard(); $this->assertInstanceOf('\Omnipay\Common\CreditCard', $card); $this->assertSame('1234', $card->getNumber()); } public function testToken() { $this->assertSame($this->request, $this->request->setToken('12345')); $this->assertSame('12345', $this->request->getToken()); } public function testCardReference() { $this->assertSame($this->request, $this->request->setCardReference('12345')); $this->assertSame('12345', $this->request->getCardReference()); } public function testAmount() { $this->assertSame($this->request, $this->request->setAmount('2.00')); $this->assertSame('2.00', $this->request->getAmount()); } public function testAmountWithFloat() { $this->assertSame($this->request, $this->request->setAmount(2.0)); $this->assertSame('2.00', $this->request->getAmount()); } public function testAmountWithEmpty() { $this->assertSame($this->request, $this->request->setAmount(null)); $this->assertSame(null, $this->request->getAmount()); } public function testGetAmountNoDecimals() { $this->assertSame($this->request, $this->request->setCurrency('JPY')); $this->assertSame($this->request, $this->request->setAmount('1366')); $this->assertSame('1366', $this->request->getAmount()); } public function testGetAmountNoDecimalsRounding() { $this->assertSame($this->request, $this->request->setAmount('136.5')); $this->assertSame($this->request, $this->request->setCurrency('JPY')); $this->assertSame('137', $this->request->getAmount()); } /** * @expectedException Omnipay\Common\Exception\InvalidRequestException */ public function testAmountWithIntThrowsException() { // ambiguous value, avoid errors upgrading from v0.9 $this->assertSame($this->request, $this->request->setAmount(10)); $this->request->getAmount(); } /** * @expectedException Omnipay\Common\Exception\InvalidRequestException */ public function testAmountWithIntStringThrowsException() { // ambiguous value, avoid errors upgrading from v0.9 $this->assertSame($this->request, $this->request->setAmount('10')); $this->request->getAmount(); } public function testGetAmountInteger() { $this->assertSame($this->request, $this->request->setAmount('13.66')); $this->assertSame(1366, $this->request->getAmountInteger()); } public function testGetAmountIntegerNoDecimals() { $this->assertSame($this->request, $this->request->setCurrency('JPY')); $this->assertSame($this->request, $this->request->setAmount('1366')); $this->assertSame(1366, $this->request->getAmountInteger()); } public function testCurrency() { $this->assertSame($this->request, $this->request->setCurrency('USD')); $this->assertSame('USD', $this->request->getCurrency()); } public function testCurrencyLowercase() { $this->assertSame($this->request, $this->request->setCurrency('usd')); $this->assertSame('USD', $this->request->getCurrency()); } public function testCurrencyNumeric() { $this->assertSame($this->request, $this->request->setCurrency('USD')); $this->assertSame('840', $this->request->getCurrencyNumeric()); } public function testCurrencyDecimals() { $this->assertSame($this->request, $this->request->setCurrency('JPY')); $this->assertSame(0, $this->request->getCurrencyDecimalPlaces()); } public function testFormatCurrency() { $this->assertSame('1234.00', $this->request->formatCurrency(1234)); } public function testFormatCurrencyNoDecimals() { $this->request->setCurrency('JPY'); $this->assertSame('1234', $this->request->formatCurrency(1234)); } public function testDescription() { $this->assertSame($this->request, $this->request->setDescription('Cool product')); $this->assertSame('Cool product', $this->request->getDescription()); } public function testTransactionId() { $this->assertSame($this->request, $this->request->setTransactionId(87)); $this->assertSame(87, $this->request->getTransactionId()); } public function testTransactionReference() { $this->assertSame($this->request, $this->request->setTransactionReference('xyz')); $this->assertSame('xyz', $this->request->getTransactionReference()); } public function testItemsArray() { $this->assertSame($this->request, $this->request->setItems(array( array('name' => 'Floppy Disk'), array('name' => 'CD-ROM'), ))); $itemBag = $this->request->getItems(); $this->assertInstanceOf('\Omnipay\Common\ItemBag', $itemBag); $items = $itemBag->all(); $this->assertSame('Floppy Disk', $items[0]->getName()); $this->assertSame('CD-ROM', $items[1]->getName()); } public function testItemsBag() { $itemBag = new ItemBag; $itemBag->add(array('name' => 'Floppy Disk')); $this->assertSame($this->request, $this->request->setItems($itemBag)); $this->assertSame($itemBag, $this->request->getItems()); } public function testClientIp() { $this->assertSame($this->request, $this->request->setClientIp('127.0.0.1')); $this->assertSame('127.0.0.1', $this->request->getClientIp()); } public function testReturnUrl() { $this->assertSame($this->request, $this->request->setReturnUrl('https://www.example.com/return')); $this->assertSame('https://www.example.com/return', $this->request->getReturnUrl()); } public function testCancelUrl() { $this->assertSame($this->request, $this->request->setCancelUrl('https://www.example.com/cancel')); $this->assertSame('https://www.example.com/cancel', $this->request->getCancelUrl()); } public function testNotifyUrl() { $this->assertSame($this->request, $this->request->setNotifyUrl('https://www.example.com/notify')); $this->assertSame('https://www.example.com/notify', $this->request->getNotifyUrl()); } public function testIssuer() { $this->assertSame($this->request, $this->request->setIssuer('some-bank')); $this->assertSame('some-bank', $this->request->getIssuer()); } public function testPaymentMethod() { $this->assertSame($this->request, $this->request->setPaymentMethod('ideal')); $this->assertSame('ideal', $this->request->getPaymentMethod()); } public function testInitializedParametersAreSet() { $params = array('testMode' => 'success'); $this->request->initialize($params); $this->assertSame($this->request->getTestMode(), 'success'); } public function testGetParameters() { $this->request->setTestMode(true); $this->request->setToken('asdf'); $expected = array( 'testMode' => true, 'token' => 'asdf', ); $this->assertEquals($expected, $this->request->getParameters()); } /** * @expectedException \Omnipay\Common\Exception\RuntimeException * @expectedExceptionMessage Request cannot be modified after it has been sent! */ public function testSetParameterAfterRequestSent() { $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->send(); $this->request->setCurrency('PHP'); } public function testCanValidateExistingParameters() { $this->request->setTestMode(true); $this->request->setToken('asdf'); $this->assertNull($this->request->validate('testMode', 'token')); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException */ public function testInvalidParametersThrowsException() { $this->request->setTestMode(true); $this->request->validate('testMode', 'token'); } public function testNoCurrencyReturnedIfCurrencyNotSet() { $this->assertNull($this->request->getCurrencyNumeric()); } public function testSend() { $response = m::mock('\Omnipay\Common\Message\ResponseInterface'); $data = array('request data'); $this->request->shouldReceive('getData')->once()->andReturn($data); $this->request->shouldReceive('sendData')->once()->with($data)->andReturn($response); $this->assertSame($response, $this->request->send()); } /** * @expectedException \Omnipay\Common\Exception\RuntimeException * @expectedExceptionMessage You must call send() before accessing the Response! */ public function testGetResponseBeforeRequestSent() { $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->getResponse(); } public function testGetResponseAfterRequestSent() { $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->send(); $response = $this->request->getResponse(); $this->assertInstanceOf('\Omnipay\Common\Message\ResponseInterface', $response); } } class AbstractRequestTest_MockAbstractRequest extends AbstractRequest { public function getData() {} public function sendData($data) { $this->response = m::mock('\Omnipay\Common\Message\AbstractResponse'); } } tests/Omnipay/Common/CreditCardTest.php 0000604 00000044407 15174372523 0014145 0 ustar 00 <?php namespace Omnipay\Common; use Omnipay\Tests\TestCase; class CreditCardTest extends TestCase { public function setUp() { $this->card = new CreditCard; $this->card->setNumber('4111111111111111'); $this->card->setFirstName('Example'); $this->card->setLastName('Customer'); $this->card->setExpiryMonth('4'); $this->card->setExpiryYear(gmdate('Y')+2); $this->card->setCvv('123'); } public function testConstructWithParams() { $card = new CreditCard(array('name' => 'Test Customer')); $this->assertSame('Test Customer', $card->getName()); } public function testInitializeWithParams() { $card = new CreditCard; $card->initialize(array('name' => 'Test Customer')); $this->assertSame('Test Customer', $card->getName()); } public function testGetParamters() { $card = new CreditCard(array( 'name' => 'Example Customer', 'number' => '1234', 'expiryMonth' => 6, 'expiryYear' => 2016, )); $parameters = $card->getParameters(); $this->assertSame('Example', $parameters['billingFirstName']); $this->assertSame('Customer', $parameters['billingLastName']); $this->assertSame('1234', $parameters['number']); $this->assertSame(6, $parameters['expiryMonth']); $this->assertSame(2016, $parameters['expiryYear']); } public function testValidateFixture() { $this->card->validate(); } /** * @expectedException \Omnipay\Common\Exception\InvalidCreditCardException * @expectedExceptionMessage The number parameter is required */ public function testValidateNumberRequired() { $this->card->setNumber(null); $this->card->validate(); } /** * @expectedException \Omnipay\Common\Exception\InvalidCreditCardException * @expectedExceptionMessage The expiryMonth parameter is required */ public function testValidateExpiryMonthRequired() { $this->card->setExpiryMonth(null); $this->card->validate(); } /** * @expectedException \Omnipay\Common\Exception\InvalidCreditCardException * @expectedExceptionMessage The expiryYear parameter is required */ public function testValidateExpiryYearRequired() { $this->card->setExpiryYear(null); $this->card->validate(); } /** * @expectedException \Omnipay\Common\Exception\InvalidCreditCardException * @expectedExceptionMessage Card has expired */ public function testValidateExpiryDate() { $this->card->setExpiryYear(gmdate('Y')-1); $this->card->validate(); } /** * @expectedException \Omnipay\Common\Exception\InvalidCreditCardException * @expectedExceptionMessage Card number is invalid */ public function testValidateNumber() { $this->card->setNumber('4111111111111110'); $this->card->validate(); } public function testGetSupportedBrands() { $brands = $this->card->getSupportedBrands(); $this->assertInternalType('array', $brands); $this->assertArrayHasKey(CreditCard::BRAND_VISA, $brands); } public function testTitle() { $this->card->setTitle('Mr.'); $this->assertEquals('Mr.', $this->card->getTitle()); } public function testFirstName() { $this->card->setFirstName('Bob'); $this->assertEquals('Bob', $this->card->getFirstName()); } public function testLastName() { $this->card->setLastName('Smith'); $this->assertEquals('Smith', $this->card->getLastName()); } public function testGetName() { $this->card->setFirstName('Bob'); $this->card->setLastName('Smith'); $this->assertEquals('Bob Smith', $this->card->getName()); } public function testSetName() { $this->card->setName('Bob Smith'); $this->assertEquals('Bob', $this->card->getFirstName()); $this->assertEquals('Smith', $this->card->getLastName()); } public function testSetNameWithOneName() { $this->card->setName('Bob'); $this->assertEquals('Bob', $this->card->getFirstName()); $this->assertEquals('', $this->card->getLastName()); } public function testSetNameWithMultipleNames() { $this->card->setName('Bob John Smith'); $this->assertEquals('Bob', $this->card->getFirstName()); $this->assertEquals('John Smith', $this->card->getLastName()); } public function testNumber() { $this->card->setNumber('4000000000000000'); $this->assertEquals('4000000000000000', $this->card->getNumber()); } public function testSetNumberStripsNonDigits() { $this->card->setNumber('4000 0000 00b00 0000'); $this->assertEquals('4000000000000000', $this->card->getNumber()); } public function testGetNumberLastFourNull() { $this->card->setNumber(null); $this->assertNull($this->card->getNumberLastFour()); } public function testGetNumberLastFour() { $this->card->setNumber('4000000000001234'); $this->assertSame('1234', $this->card->getNumberLastFour()); } public function testGetNumberLastFourNonDigits() { $this->card->setNumber('4000 0000 0000 12x34'); $this->assertSame('1234', $this->card->getNumberLastFour()); } public function testGetNumberMasked() { $this->card->setNumber('4000000000001234'); $this->assertSame('XXXXXXXXXXXX1234', $this->card->getNumberMasked()); } public function testGetNumberMaskedNonDigits() { $this->card->setNumber('4000 0000 0000 12x34'); $this->assertSame('XXXXXXXXXXXX1234', $this->card->getNumberMasked()); } public function testGetBrandDefault() { $card = new CreditCard; $this->assertNull($card->getBrand()); } public function testGetBrandVisa() { $card = new CreditCard(array('number' => '4242424242424242')); $this->assertSame(CreditCard::BRAND_VISA, $card->getBrand()); } public function testGetBrandMasterCard() { $card = new CreditCard(array('number' => '5555555555554444')); $this->assertSame(CreditCard::BRAND_MASTERCARD, $card->getBrand()); } public function testGetBrandAmex() { $card = new CreditCard(array('number' => '378282246310005')); $this->assertSame(CreditCard::BRAND_AMEX, $card->getBrand()); } public function testGetBrandDiscover() { $card = new CreditCard(array('number' => '6011111111111117')); $this->assertSame(CreditCard::BRAND_DISCOVER, $card->getBrand()); } public function testGetBrandDinersClub() { $card = new CreditCard(array('number' => '30569309025904')); $this->assertSame(CreditCard::BRAND_DINERS_CLUB, $card->getBrand()); } public function testGetBrandJcb() { $card = new CreditCard(array('number' => '3530111333300000')); $this->assertSame(CreditCard::BRAND_JCB, $card->getBrand()); } public function testExpiryMonth() { $this->card->setExpiryMonth(9); $this->assertSame(9, $this->card->getExpiryMonth()); } public function testExpiryMonthLeadingZeros() { $this->card->setExpiryMonth('09'); $this->assertSame(9, $this->card->getExpiryMonth()); } public function testExpiryYear() { $this->card->setExpiryYear(2012); $this->assertSame(2012, $this->card->getExpiryYear()); } public function testExpiryYearTwoDigits() { $this->card->setExpiryYear('12'); $this->assertSame(2012, $this->card->getExpiryYear()); } public function testExpiryDate() { $this->assertSame($this->card, $this->card->setExpiryMonth('09')); $this->assertSame($this->card, $this->card->setExpiryYear('2012')); $this->assertSame('092012', $this->card->getExpiryDate('mY')); } public function testStartMonth() { $this->card->setStartMonth(9); $this->assertSame(9, $this->card->getStartMonth()); } public function testStartMonthLeadingZeros() { $this->card->setStartMonth('09'); $this->assertSame(9, $this->card->getStartMonth()); } public function testStartYear() { $this->card->setStartYear(2012); $this->assertSame(2012, $this->card->getStartYear()); } public function testStartYearTwoDigits() { $this->card->setStartYear('12'); $this->assertSame(2012, $this->card->getStartYear()); } public function testStartDate() { $this->card->setStartMonth('11'); $this->card->setStartYear('2012'); $this->assertEquals('112012', $this->card->getStartDate('mY')); } public function testCvv() { $this->card->setCvv('456'); $this->assertEquals('456', $this->card->getCvv()); } public function testIssueNumber() { $this->card->setIssueNumber('12'); $this->assertSame('12', $this->card->getIssueNumber()); } public function testBillingTitle() { $this->card->setBillingTitle('Mrs.'); $this->assertEquals('Mrs.', $this->card->getBillingTitle()); $this->assertEquals('Mrs.', $this->card->getTitle()); } public function testBillingFirstName() { $this->card->setBillingFirstName('Bob'); $this->assertEquals('Bob', $this->card->getBillingFirstName()); $this->assertEquals('Bob', $this->card->getFirstName()); } public function testBillingLastName() { $this->card->setBillingLastName('Smith'); $this->assertEquals('Smith', $this->card->getBillingLastName()); $this->assertEquals('Smith', $this->card->getLastName()); } public function testBillingName() { $this->card->setBillingFirstName('Bob'); $this->card->setBillingLastName('Smith'); $this->assertEquals('Bob Smith', $this->card->getBillingName()); $this->card->setBillingName('John Foo'); $this->assertEquals('John', $this->card->getBillingFirstName()); $this->assertEquals('Foo', $this->card->getBillingLastName()); } public function testBillingCompany() { $this->card->setBillingCompany('SuperSoft'); $this->assertEquals('SuperSoft', $this->card->getBillingCompany()); $this->assertEquals('SuperSoft', $this->card->getCompany()); } public function testBillingAddress1() { $this->card->setBillingAddress1('31 Spooner St'); $this->assertEquals('31 Spooner St', $this->card->getBillingAddress1()); $this->assertEquals('31 Spooner St', $this->card->getAddress1()); } public function testBillingAddress2() { $this->card->setBillingAddress2('Suburb'); $this->assertEquals('Suburb', $this->card->getBillingAddress2()); $this->assertEquals('Suburb', $this->card->getAddress2()); } public function testBillingCity() { $this->card->setBillingCity('Quahog'); $this->assertEquals('Quahog', $this->card->getBillingCity()); $this->assertEquals('Quahog', $this->card->getCity()); } public function testBillingPostcode() { $this->card->setBillingPostcode('12345'); $this->assertEquals('12345', $this->card->getBillingPostcode()); $this->assertEquals('12345', $this->card->getPostcode()); } public function testBillingState() { $this->card->setBillingState('RI'); $this->assertEquals('RI', $this->card->getBillingState()); $this->assertEquals('RI', $this->card->getState()); } public function testBillingCountry() { $this->card->setBillingCountry('US'); $this->assertEquals('US', $this->card->getBillingCountry()); $this->assertEquals('US', $this->card->getCountry()); } public function testBillingPhone() { $this->card->setBillingPhone('12345'); $this->assertSame('12345', $this->card->getBillingPhone()); $this->assertSame('12345', $this->card->getPhone()); } public function testBillingFax() { $this->card->setBillingFax('54321'); $this->assertSame('54321', $this->card->getBillingFax()); $this->assertSame('54321', $this->card->getFax()); } public function testShippingTitle() { $this->card->setShippingTitle('Dr.'); $this->assertEquals('Dr.', $this->card->getShippingTitle()); } public function testShippingFirstName() { $this->card->setShippingFirstName('James'); $this->assertEquals('James', $this->card->getShippingFirstName()); } public function testShippingLastName() { $this->card->setShippingLastName('Doctor'); $this->assertEquals('Doctor', $this->card->getShippingLastName()); } public function testShippingName() { $this->card->setShippingFirstName('Bob'); $this->card->setShippingLastName('Smith'); $this->assertEquals('Bob Smith', $this->card->getShippingName()); $this->card->setShippingName('John Foo'); $this->assertEquals('John', $this->card->getShippingFirstName()); $this->assertEquals('Foo', $this->card->getShippingLastName()); } public function testShippingCompany() { $this->card->setShippingCompany('SuperSoft'); $this->assertEquals('SuperSoft', $this->card->getShippingCompany()); } public function testShippingAddress1() { $this->card->setShippingAddress1('31 Spooner St'); $this->assertEquals('31 Spooner St', $this->card->getShippingAddress1()); } public function testShippingAddress2() { $this->card->setShippingAddress2('Suburb'); $this->assertEquals('Suburb', $this->card->getShippingAddress2()); } public function testShippingCity() { $this->card->setShippingCity('Quahog'); $this->assertEquals('Quahog', $this->card->getShippingCity()); } public function testShippingPostcode() { $this->card->setShippingPostcode('12345'); $this->assertEquals('12345', $this->card->getShippingPostcode()); } public function testShippingState() { $this->card->setShippingState('RI'); $this->assertEquals('RI', $this->card->getShippingState()); } public function testShippingCountry() { $this->card->setShippingCountry('US'); $this->assertEquals('US', $this->card->getShippingCountry()); } public function testShippingPhone() { $this->card->setShippingPhone('12345'); $this->assertEquals('12345', $this->card->getShippingPhone()); } public function testShippingFax() { $this->card->setShippingFax('54321'); $this->assertEquals('54321', $this->card->getShippingFax()); } public function testCompany() { $this->card->setCompany('FooBar'); $this->assertEquals('FooBar', $this->card->getCompany()); $this->assertEquals('FooBar', $this->card->getBillingCompany()); $this->assertEquals('FooBar', $this->card->getShippingCompany()); } public function testAddress1() { $this->card->setAddress1('31 Spooner St'); $this->assertEquals('31 Spooner St', $this->card->getAddress1()); $this->assertEquals('31 Spooner St', $this->card->getBillingAddress1()); $this->assertEquals('31 Spooner St', $this->card->getShippingAddress1()); } public function testAddress2() { $this->card->setAddress2('Suburb'); $this->assertEquals('Suburb', $this->card->getAddress2()); $this->assertEquals('Suburb', $this->card->getBillingAddress2()); $this->assertEquals('Suburb', $this->card->getShippingAddress2()); } public function testCity() { $this->card->setCity('Quahog'); $this->assertEquals('Quahog', $this->card->getCity()); $this->assertEquals('Quahog', $this->card->getBillingCity()); $this->assertEquals('Quahog', $this->card->getShippingCity()); } public function testPostcode() { $this->card->setPostcode('12345'); $this->assertEquals('12345', $this->card->getPostcode()); $this->assertEquals('12345', $this->card->getBillingPostcode()); $this->assertEquals('12345', $this->card->getShippingPostcode()); } public function testState() { $this->card->setState('RI'); $this->assertEquals('RI', $this->card->getState()); $this->assertEquals('RI', $this->card->getBillingState()); $this->assertEquals('RI', $this->card->getShippingState()); } public function testCountry() { $this->card->setCountry('US'); $this->assertEquals('US', $this->card->getCountry()); $this->assertEquals('US', $this->card->getBillingCountry()); $this->assertEquals('US', $this->card->getShippingCountry()); } public function testPhone() { $this->card->setPhone('12345'); $this->assertEquals('12345', $this->card->getPhone()); $this->assertEquals('12345', $this->card->getBillingPhone()); $this->assertEquals('12345', $this->card->getShippingPhone()); } public function testFax() { $this->card->setFax('54321'); $this->assertEquals('54321', $this->card->getFax()); $this->assertEquals('54321', $this->card->getBillingFax()); $this->assertEquals('54321', $this->card->getShippingFax()); } public function testEmail() { $this->card->setEmail('adrian@example.com'); $this->assertEquals('adrian@example.com', $this->card->getEmail()); } public function testBirthday() { $this->card->setBirthday('01-02-2000'); $this->assertEquals('2000-02-01', $this->card->getBirthday()); $this->assertEquals('01/02/2000', $this->card->getBirthday('d/m/Y')); } public function testBirthdayEmpty() { $this->card->setBirthday(''); $this->assertNull($this->card->getBirthday()); } public function testGender() { $this->card->setGender('female'); $this->assertEquals('female', $this->card->getGender()); } /** * @expectedException Omnipay\Common\Exception\InvalidCreditCardException */ public function testInvalidShortCard() { $this->card->setNumber('43'); $this->card->validate(); } } tests/Omnipay/Common/HelperTest.php 0000604 00000010002 15174372523 0013340 0 ustar 00 <?php namespace Omnipay\Common; use Mockery as m; use Omnipay\Tests\TestCase; class HelperTest extends TestCase { public function testCamelCase() { $result = Helper::camelCase('test_case'); $this->assertEquals('testCase', $result); } public function testCamelCaseAlreadyCorrect() { $result = Helper::camelCase('testCase'); $this->assertEquals('testCase', $result); } public function testValidateLuhnValid() { $result = Helper::validateLuhn('4111111111111111'); $this->assertTrue($result); } public function testValidateLuhnInvalid() { $result = Helper::validateLuhn('4111111111111110'); $this->assertFalse($result); } public function testValidateLuhnNull() { $result = Helper::validateLuhn(null); $this->assertTrue($result); } public function testInitializeIgnoresNull() { $target = m::mock(); Helper::initialize($target, null); } public function testInitializeIgnoresString() { $target = m::mock(); Helper::initialize($target, 'invalid'); } public function testInitializeCallsSetters() { $target = m::mock('\Omnipay\Common\CreditCard'); $target->shouldReceive('setName')->once()->with('adrian'); $target->shouldReceive('setNumber')->once()->with('1234'); Helper::initialize($target, array('name' => 'adrian', 'number' => '1234')); } public function testInitializeIgnoresInvalidParameters() { $target = m::mock('\Omnipay\Common\CreditCard'); $target->shouldReceive('setName')->once()->with('adrian'); Helper::initialize($target, array('name' => 'adrian', 'extra' => 'invalid')); } public function testGetGatewayShortNameSimple() { $shortName = Helper::getGatewayShortName('Omnipay\\Stripe\\Gateway'); $this->assertSame('Stripe', $shortName); } public function testGetGatewayShortNameSimpleLeadingSlash() { $shortName = Helper::getGatewayShortName('\\Omnipay\\Stripe\\Gateway'); $this->assertSame('Stripe', $shortName); } public function testGetGatewayShortNameUnderscore() { $shortName = Helper::getGatewayShortName('Omnipay\\PayPal\\ExpressGateway'); $this->assertSame('PayPal_Express', $shortName); } public function testGetGatewayShortNameUnderscoreLeadingSlash() { $shortName = Helper::getGatewayShortName('\\Omnipay\\PayPal\\ExpressGateway'); $this->assertSame('PayPal_Express', $shortName); } public function testGetGatewayShortNameCustomGateway() { $shortName = Helper::getGatewayShortName('\\Custom\\Gateway'); $this->assertSame('\\Custom\\Gateway', $shortName); } /** * Type with namespace should simply be returned as is */ public function testGetGatewayClassNameExistingNamespace() { $class = Helper::getGatewayClassName('\\Custom\\Gateway'); $this->assertEquals('\\Custom\\Gateway', $class); } /** * Type with namespace marker should be left intact, even if it contains an underscore */ public function testGetGatewayClassNameExistingNamespaceUnderscore() { $class = Helper::getGatewayClassName('\\Custom_Gateway'); $this->assertEquals('\\Custom_Gateway', $class); } public function testGetGatewayClassNameSimple() { $class = Helper::getGatewayClassName('Stripe'); $this->assertEquals('\\Omnipay\\Stripe\\Gateway', $class); } public function testGetGatewayClassNamePartialNamespace() { $class = Helper::getGatewayClassName('PayPal\\Express'); $this->assertEquals('\\Omnipay\\PayPal\\ExpressGateway', $class); } /** * Underscored types should be resolved in a PSR-0 fashion */ public function testGetGatewayClassNameUnderscoreNamespace() { $class = Helper::getGatewayClassName('PayPal_Express'); $this->assertEquals('\\Omnipay\\PayPal\\ExpressGateway', $class); } } tests/Omnipay/Common/ItemTest.php 0000604 00000002434 15174372523 0013031 0 ustar 00 <?php namespace Omnipay\Common; use Omnipay\Tests\TestCase; class ItemTest extends TestCase { public function setUp() { $this->item = new Item; } public function testConstructWithParams() { $item = new Item(array('name' => 'Floppy Disk')); $this->assertSame('Floppy Disk', $item->getName()); } public function testInitializeWithParams() { $this->item->initialize(array('name' => 'Floppy Disk')); $this->assertSame('Floppy Disk', $this->item->getName()); } public function testGetParameters() { $this->item->setName('CD-ROM'); $this->assertSame(array('name' => 'CD-ROM'), $this->item->getParameters()); } public function testName() { $this->item->setName('CD-ROM'); $this->assertSame('CD-ROM', $this->item->getName()); } public function testDescription() { $this->item->setDescription('CD'); $this->assertSame('CD', $this->item->getDescription()); } public function testQuantity() { $this->item->setQuantity(5); $this->assertSame(5, $this->item->getQuantity()); } public function testPrice() { $this->item->setPrice('10.01'); $this->assertSame('10.01', $this->item->getPrice()); } } tests/Omnipay/OmnipayTest.php 0000604 00000001712 15174372523 0012315 0 ustar 00 <?php namespace Omnipay; use Mockery as m; use Omnipay\Tests\TestCase; class OmnipayTest extends TestCase { public function tearDown() { Omnipay::setFactory(null); } public function testGetFactory() { Omnipay::setFactory(null); $factory = Omnipay::getFactory(); $this->assertInstanceOf('Omnipay\Common\GatewayFactory', $factory); } public function testSetFactory() { $factory = m::mock('Omnipay\Common\GatewayFactory'); Omnipay::setFactory($factory); $this->assertSame($factory, Omnipay::getFactory()); } public function testCallStatic() { $factory = m::mock('Omnipay\Common\GatewayFactory'); $factory->shouldReceive('testMethod')->with('some-argument')->once()->andReturn('some-result'); Omnipay::setFactory($factory); $result = Omnipay::testMethod('some-argument'); $this->assertSame('some-result', $result); } } tests/bootstrap.php 0000604 00000000410 15174372523 0010434 0 ustar 00 <?php error_reporting(E_ALL | E_STRICT); date_default_timezone_set('UTC'); // include the composer autoloader $autoloader = require __DIR__.'/../vendor/autoload.php'; // autoload abstract TestCase classes in test directory $autoloader->add('Omnipay', __DIR__); README.md 0000604 00000002463 15174372523 0006035 0 ustar 00 # Omnipay Common **Core components for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-common) [](https://packagist.org/packages/omnipay/common) [](https://packagist.org/packages/omnipay/common) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements common classes required by Omnipay. ## Support If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to. If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-common/issues), or better yet, fork the library and submit a pull request. LICENSE 0000604 00000002047 15174372523 0005561 0 ustar 00 Copyright (c) 2012-2013 Adrian Macneil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. makedoc.sh 0000604 00000001002 15174372523 0006501 0 ustar 00 #!/bin/sh mkdir -p ./reports mkdir -p ./documents/apigen if [ -z "$1" ]; then apigen \ --title 'Onmipay Common API documentation' \ --source ./src \ --destination ./documents/apigen \ --report ./reports/apigen.xml # # Left here for further expansion, ignore this for the time being. # elif [ "$1" = "common" ]; then apigen \ --title 'Omnipay Common API documentation' \ --source ./src/Omnipay/Common \ --destination ./documents/apigen \ --report ./reports/apigen.xml fi .travis.yml 0000604 00000001036 15174372523 0006662 0 ustar 00 language: php php: - 5.3 - 5.4 - 5.5 - 5.6 - hhvm env: - SYMFONY_VERSION="2.1" GUZZLE_VERSION="3.1" - SYMFONY_VERSION="2.*" GUZZLE_VERSION="3.1" - SYMFONY_VERSION="2.1" GUZZLE_VERSION="3.*" - SYMFONY_VERSION="2.*" GUZZLE_VERSION="3.*" before_script: - composer require symfony/http-foundation:${SYMFONY_VERSION} --no-update - composer require guzzle/guzzle:${GUZZLE_VERSION} --no-update - composer install -n --dev --prefer-source script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text CONTRIBUTING.md 0000604 00000001040 15174372523 0006775 0 ustar 00 # Contributing Guidelines * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files. * Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) style and that all tests pass. * Send the pull request. * Check that the Travis CI build passed. If not, rinse and repeat. src/Omnipay/Common/PaymentMethod.php 0000604 00000002117 15174372523 0013474 0 ustar 00 <?php /** * Payment Method */ namespace Omnipay\Common; /** * Payment Method * * This class defines a payment method to be used in the Omnipay system. * * @see Issuer */ class PaymentMethod { /** * The ID of the payment method. Used as the payment method ID in the * Issuer class. * * @see Issuer * * @var string */ protected $id; /** * The full name of the payment method * * @var string */ protected $name; /** * Create a new PaymentMethod * * @param string $id The identifier of this payment method * @param string $name The name of this payment method */ public function __construct($id, $name) { $this->id = $id; $this->name = $name; } /** * The identifier of this payment method * * @return string */ public function getId() { return $this->id; } /** * The name of this payment method * * @return string */ public function getName() { return $this->name; } } src/Omnipay/Common/AbstractGateway.php 0000604 00000016470 15174372523 0014012 0 ustar 00 <?php /** * Base payment gateway class */ namespace Omnipay\Common; use Guzzle\Http\ClientInterface; use Guzzle\Http\Client as HttpClient; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Base payment gateway class * * This abstract class should be extended by all payment gateways * throughout the Omnipay system. It enforces implementation of * the GatewayInterface interface and defines various common attibutes * and methods that all gateways should have. * * Example: * * <code> * // Initialise the gateway * $gateway->initialize(...); * * // Get the gateway parameters. * $parameters = $gateway->getParameters(); * * // Create a credit card object * $card = new CreditCard(...); * * // Do an authorisation transaction on the gateway * if ($gateway->supportsAuthorize()) { * $gateway->authorize(...); * } else { * throw new \Exception('Gateway does not support authorize()'); * } * </code> * * For further code examples see the *omnipay-example* repository on github. * * @see GatewayInterface */ abstract class AbstractGateway implements GatewayInterface { /** * @var \Symfony\Component\HttpFoundation\ParameterBag */ protected $parameters; /** * @var \Guzzle\Http\ClientInterface */ protected $httpClient; /** * @var \Symfony\Component\HttpFoundation\Request */ protected $httpRequest; /** * Create a new gateway instance * * @param ClientInterface $httpClient A Guzzle client to make API calls with * @param HttpRequest $httpRequest A Symfony HTTP request object */ public function __construct(ClientInterface $httpClient = null, HttpRequest $httpRequest = null) { $this->httpClient = $httpClient ?: $this->getDefaultHttpClient(); $this->httpRequest = $httpRequest ?: $this->getDefaultHttpRequest(); $this->initialize(); } public function getShortName() { return Helper::getGatewayShortName(get_class($this)); } public function initialize(array $parameters = array()) { $this->parameters = new ParameterBag; // set default parameters foreach ($this->getDefaultParameters() as $key => $value) { if (is_array($value)) { $this->parameters->set($key, reset($value)); } else { $this->parameters->set($key, $value); } } Helper::initialize($this, $parameters); return $this; } public function getDefaultParameters() { return array(); } public function getParameters() { return $this->parameters->all(); } protected function getParameter($key) { return $this->parameters->get($key); } protected function setParameter($key, $value) { $this->parameters->set($key, $value); return $this; } public function getTestMode() { return $this->getParameter('testMode'); } public function setTestMode($value) { return $this->setParameter('testMode', $value); } public function getCurrency() { return strtoupper($this->getParameter('currency')); } public function setCurrency($value) { return $this->setParameter('currency', $value); } /** * Supports Authorize * * @return boolean True if this gateway supports the authorize() method */ public function supportsAuthorize() { return method_exists($this, 'authorize'); } /** * Supports Complete Authorize * * @return boolean True if this gateway supports the completeAuthorize() method */ public function supportsCompleteAuthorize() { return method_exists($this, 'completeAuthorize'); } /** * Supports Capture * * @return boolean True if this gateway supports the capture() method */ public function supportsCapture() { return method_exists($this, 'capture'); } /** * Supports Purchase * * @return boolean True if this gateway supports the purchase() method */ public function supportsPurchase() { return method_exists($this, 'purchase'); } /** * Supports Complete Purchase * * @return boolean True if this gateway supports the completePurchase() method */ public function supportsCompletePurchase() { return method_exists($this, 'completePurchase'); } /** * Supports Refund * * @return boolean True if this gateway supports the refund() method */ public function supportsRefund() { return method_exists($this, 'refund'); } /** * Supports Void * * @return boolean True if this gateway supports the void() method */ public function supportsVoid() { return method_exists($this, 'void'); } /** * Supports CreateCard * * @return boolean True if this gateway supports the create() method */ public function supportsCreateCard() { return method_exists($this, 'createCard'); } /** * Supports DeleteCard * * @return boolean True if this gateway supports the delete() method */ public function supportsDeleteCard() { return method_exists($this, 'deleteCard'); } /** * Supports UpdateCard * * @return boolean True if this gateway supports the update() method */ public function supportsUpdateCard() { return method_exists($this, 'updateCard'); } /** * Create and initialize a request object * * This function is usually used to create objects of type * Omnipay\Common\Message\AbstractRequest (or a non-abstract subclass of it) * and initialise them with using existing parameters from this gateway. * * Example: * * <code> * class MyRequest extends \Omnipay\Common\Message\AbstractRequest {}; * * class MyGateway extends \Omnipay\Common\AbstractGateway { * function myRequest($parameters) { * $this->createRequest('MyRequest', $parameters); * } * } * * // Create the gateway object * $gw = Omnipay::create('MyGateway'); * * // Create the request object * $myRequest = $gw->myRequest($someParameters); * </code> * * @see \Omnipay\Common\Message\AbstractRequest * @param string $class The request class name * @param array $parameters * @return \Omnipay\Common\Message\AbstractRequest */ protected function createRequest($class, array $parameters) { $obj = new $class($this->httpClient, $this->httpRequest); return $obj->initialize(array_replace($this->getParameters(), $parameters)); } /** * Get the global default HTTP client. * * @return HttpClient */ protected function getDefaultHttpClient() { return new HttpClient( '', array( 'curl.options' => array(CURLOPT_CONNECTTIMEOUT => 60), ) ); } /** * Get the global default HTTP request. * * @return HttpRequest */ protected function getDefaultHttpRequest() { return HttpRequest::createFromGlobals(); } } src/Omnipay/Common/Issuer.php 0000604 00000003041 15174372523 0012165 0 ustar 00 <?php /** * Issuer */ namespace Omnipay\Common; /** * Issuer * * This class abstracts some functionality around card issuers used in the * Omnipay system. */ class Issuer { /** * The identifier of the issuer. * * @var string */ protected $id; /** * The full name of the issuer. * * @var string */ protected $name; /** * The ID of a payment method that the issuer belongs to. * * @see PaymentMethod * * @var string */ protected $paymentMethod; /** * Create a new Issuer * * @see PaymentMethod * * @param string $id The identifier of this issuer * @param string $name The name of this issuer * @param string|null $paymentMethod The ID of a payment method this issuer belongs to */ public function __construct($id, $name, $paymentMethod = null) { $this->id = $id; $this->name = $name; $this->paymentMethod = $paymentMethod; } /** * The identifier of this issuer * * @return string */ public function getId() { return $this->id; } /** * The name of this issuer * * @return string */ public function getName() { return $this->name; } /** * The ID of a payment method this issuer belongs to * * @see PaymentMethod * * @return string */ public function getPaymentMethod() { return $this->paymentMethod; } } src/Omnipay/Common/ItemInterface.php 0000604 00000001034 15174372523 0013432 0 ustar 00 <?php /** * Cart Item interface */ namespace Omnipay\Common; /** * Cart Item interface * * This interface defines the functionality that all cart items in * the Omnipay system are to have. */ interface ItemInterface { /** * Name of the item */ public function getName(); /** * Description of the item */ public function getDescription(); /** * Quantity of the item */ public function getQuantity(); /** * Price of the item */ public function getPrice(); } src/Omnipay/Common/Exception/BadMethodCallException.php 0000604 00000000256 15174372523 0017160 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Bad Method Call Exception */ class BadMethodCallException extends \BadMethodCallException implements OmnipayException { } src/Omnipay/Common/Exception/InvalidRequestException.php 0000604 00000000345 15174372523 0017473 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Invalid Request Exception * * Thrown when a request is invalid or missing required fields. */ class InvalidRequestException extends \Exception implements OmnipayException { } src/Omnipay/Common/Exception/OmnipayException.php 0000604 00000000171 15174372523 0016145 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Omnipay Exception marker interface */ interface OmnipayException { } src/Omnipay/Common/Exception/InvalidCreditCardException.php 0000604 00000000360 15174372523 0020044 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Invalid Credit Card Exception * * Thrown when a credit card is invalid or missing required fields. */ class InvalidCreditCardException extends \Exception implements OmnipayException { } src/Omnipay/Common/Exception/RuntimeException.php 0000604 00000000232 15174372523 0016152 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Runtime Exception */ class RuntimeException extends \RuntimeException implements OmnipayException { } src/Omnipay/Common/Exception/InvalidResponseException.php 0000604 00000000717 15174372523 0017644 0 ustar 00 <?php namespace Omnipay\Common\Exception; /** * Invalid Response exception. * * Thrown when a gateway responded with invalid or unexpected data (for example, a security hash did not match). */ class InvalidResponseException extends \Exception implements OmnipayException { public function __construct($message = "Invalid response from payment gateway", $code = 0, $previous = null) { parent::__construct($message, $code, $previous); } } src/Omnipay/Common/ItemBag.php 0000604 00000003455 15174372523 0012234 0 ustar 00 <?php /** * Cart Item Bag */ namespace Omnipay\Common; /** * Cart Item Bag * * This class defines a bag (multi element set or array) of single cart items * in the Omnipay system. * * @see Item */ class ItemBag implements \IteratorAggregate, \Countable { /** * Item storage * * @see Item * * @var array */ protected $items; /** * Constructor * * @param array $items An array of items */ public function __construct(array $items = array()) { $this->replace($items); } /** * Return all the items * * @see Item * * @return array An array of items */ public function all() { return $this->items; } /** * Replace the contents of this bag with the specified items * * @see Item * * @param array $items An array of items */ public function replace(array $items = array()) { $this->items = array(); foreach ($items as $item) { $this->add($item); } } /** * Add an item to the bag * * @see Item * * @param ItemInterface|array $item An existing item, or associative array of item parameters */ public function add($item) { if ($item instanceof ItemInterface) { $this->items[] = $item; } else { $this->items[] = new Item($item); } } /** * Returns an iterator for items * * @return \ArrayIterator An \ArrayIterator instance */ public function getIterator() { return new \ArrayIterator($this->items); } /** * Returns the number of items * * @return int The number of items */ public function count() { return count($this->items); } } src/Omnipay/Common/Message/FetchPaymentMethodsResponseInterface.php 0000604 00000001610 15174372523 0021552 0 ustar 00 <?php /** * Fetch Payment Methods Response interface */ namespace Omnipay\Common\Message; /** * Fetch Payment Methods Response interface * * This interface class defines the functionality of a response * that is a "fetch payment method" response. It extends the ResponseInterface * interface class with some extra functions relating to the * specifics of a response to fetch the payment method from the gateway. * This happens when the gateway needs the customer to choose a * payment method. * * @see ResponseInterface * @see Omnipay\Common\PaymentMethod */ interface FetchPaymentMethodsResponseInterface extends ResponseInterface { /** * Get the returned list of payment methods. * * These represent separate payment methods which the user must choose between. * * @return \Omnipay\Common\PaymentMethod[] */ public function getPaymentMethods(); } src/Omnipay/Common/Message/MessageInterface.php 0000604 00000000777 15174372523 0015521 0 ustar 00 <?php /** * Message Interface */ namespace Omnipay\Common\Message; /** * Message Interface * * This interface class defines the standard functions that any Omnipay message * interface needs to be able to provide. */ interface MessageInterface { /** * Get the raw data array for this message. The format of this varies from gateway to * gateway, but will usually be either an associative array, or a SimpleXMLElement. * * @return mixed */ public function getData(); } src/Omnipay/Common/Message/AbstractRequest.php 0000604 00000034363 15174372523 0015426 0 ustar 00 <?php /** * Abstract Request */ namespace Omnipay\Common\Message; use Guzzle\Http\ClientInterface; use Omnipay\Common\CreditCard; use Omnipay\Common\Currency; use Omnipay\Common\Exception\InvalidRequestException; use Omnipay\Common\Exception\RuntimeException; use Omnipay\Common\Helper; use Omnipay\Common\ItemBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Abstract Request * * This abstract class implements RequestInterface and defines a basic * set of functions that all Omnipay Requests are intended to include. * * Requests of this class are usually created using the createRequest * function of the gateway and then actioned using methods within this * class or a class that extends this class. * * Example -- creating a request: * * <code> * class MyRequest extends \Omnipay\Common\Message\AbstractRequest {}; * * class MyGateway extends \Omnipay\Common\AbstractGateway { * function myRequest($parameters) { * $this->createRequest('MyRequest', $parameters); * } * } * * // Create the gateway object * $gw = Omnipay::create('MyGateway'); * * // Create the request object * $myRequest = $gw->myRequest($someParameters); * </code> * * Example -- validating and sending a request: * * <code> * try { * $myRequest->validate(); * $myResponse = $myRequest->send(); * } catch (InvalidRequestException $e) { * print "Something went wrong: " . $e->getMessage() . "\n"; * } * // now do something with the $myResponse object, test for success, etc. * </code> * * @see RequestInterface * @see AbstractResponse */ abstract class AbstractRequest implements RequestInterface { /** * The request parameters * * @var \Symfony\Component\HttpFoundation\ParameterBag */ protected $parameters; /** * The request client. * * @var \Guzzle\Http\ClientInterface */ protected $httpClient; /** * The HTTP request object. * * @var \Symfony\Component\HttpFoundation\Request */ protected $httpRequest; /** * An associated ResponseInterface. * * @var ResponseInterface */ protected $response; /** * Create a new Request * * @param ClientInterface $httpClient A Guzzle client to make API calls with * @param HttpRequest $httpRequest A Symfony HTTP request object */ public function __construct(ClientInterface $httpClient, HttpRequest $httpRequest) { $this->httpClient = $httpClient; $this->httpRequest = $httpRequest; $this->initialize(); } /** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array $parameters An associative array of parameters * * @return $this * @throws RuntimeException */ public function initialize(array $parameters = array()) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); } $this->parameters = new ParameterBag; Helper::initialize($this, $parameters); return $this; } /** * Get all parameters as an associative array. * * @return array */ public function getParameters() { return $this->parameters->all(); } /** * Get a single parameter. * * @param string $key The parameter key * @return mixed */ protected function getParameter($key) { return $this->parameters->get($key); } /** * Set a single parameter * * @param string $key The parameter key * @param mixed $value The value to set * @return AbstractRequest Provides a fluent interface * @throws RuntimeException if a request parameter is modified after the request has been sent. */ protected function setParameter($key, $value) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); } $this->parameters->set($key, $value); return $this; } /** * Gets the test mode of the request from the gateway. * * @return boolean */ public function getTestMode() { return $this->getParameter('testMode'); } /** * Sets the test mode of the request. * * @param boolean $value True for test mode on. */ public function setTestMode($value) { return $this->setParameter('testMode', $value); } /** * Validate the request. * * This method is called internally by gateways to avoid wasting time with an API call * when the request is clearly invalid. * * @param string ... a variable length list of required parameters * @throws InvalidRequestException */ public function validate() { foreach (func_get_args() as $key) { $value = $this->parameters->get($key); if (empty($value)) { throw new InvalidRequestException("The $key parameter is required"); } } } /** * Get the card. * * @return CreditCard */ public function getCard() { return $this->getParameter('card'); } /** * Sets the card. * * @param CreditCard $value * @return AbstractRequest Provides a fluent interface */ public function setCard($value) { if ($value && !$value instanceof CreditCard) { $value = new CreditCard($value); } return $this->setParameter('card', $value); } /** * Get the card token. * * @return string */ public function getToken() { return $this->getParameter('token'); } /** * Sets the card token. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setToken($value) { return $this->setParameter('token', $value); } /** * Get the card reference. * * @return string */ public function getCardReference() { return $this->getParameter('cardReference'); } /** * Sets the card reference. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setCardReference($value) { return $this->setParameter('cardReference', $value); } /** * Get the payment amount. * * @return string */ public function getAmount() { $amount = $this->getParameter('amount'); if ($amount !== null) { if (!is_float($amount) && $this->getCurrencyDecimalPlaces() > 0 && false === strpos((string) $amount, '.')) { throw new InvalidRequestException( 'Please specify amount as a string or float, ' . 'with decimal places (e.g. \'10.00\' to represent $10.00).' ); } return $this->formatCurrency($amount); } } /** * Sets the payment amount. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setAmount($value) { return $this->setParameter('amount', $value); } /** * Get the payment amount as an integer. * * @return integer */ public function getAmountInteger() { return (int) round($this->getAmount() * $this->getCurrencyDecimalFactor()); } /** * Get the payment currency code. * * @return string */ public function getCurrency() { return $this->getParameter('currency'); } /** * Sets the payment currency code. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setCurrency($value) { return $this->setParameter('currency', strtoupper($value)); } /** * Get the payment currency number. * * @return integer */ public function getCurrencyNumeric() { if ($currency = Currency::find($this->getCurrency())) { return $currency->getNumeric(); } } /** * Get the number of decimal places in the payment currency. * * @return integer */ public function getCurrencyDecimalPlaces() { if ($currency = Currency::find($this->getCurrency())) { return $currency->getDecimals(); } return 2; } private function getCurrencyDecimalFactor() { return pow(10, $this->getCurrencyDecimalPlaces()); } /** * Format an amount for the payment currency. * * @return string */ public function formatCurrency($amount) { return number_format( $amount, $this->getCurrencyDecimalPlaces(), '.', '' ); } /** * Get the request description. * * @return string */ public function getDescription() { return $this->getParameter('description'); } /** * Sets the request description. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setDescription($value) { return $this->setParameter('description', $value); } /** * Get the transaction ID. * * @return string */ public function getTransactionId() { return $this->getParameter('transactionId'); } /** * Sets the transaction ID. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setTransactionId($value) { return $this->setParameter('transactionId', $value); } /** * Get the transaction reference. * * @return string */ public function getTransactionReference() { return $this->getParameter('transactionReference'); } /** * Sets the transaction reference. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setTransactionReference($value) { return $this->setParameter('transactionReference', $value); } /** * A list of items in this order * * @return ItemBag|null A bag containing items in this order */ public function getItems() { return $this->getParameter('items'); } /** * Set the items in this order * * @param ItemBag|array $items An array of items in this order */ public function setItems($items) { if ($items && !$items instanceof ItemBag) { $items = new ItemBag($items); } return $this->setParameter('items', $items); } /** * Get the client IP address. * * @return string */ public function getClientIp() { return $this->getParameter('clientIp'); } /** * Sets the client IP address. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setClientIp($value) { return $this->setParameter('clientIp', $value); } /** * Get the request return URL. * * @return string */ public function getReturnUrl() { return $this->getParameter('returnUrl'); } /** * Sets the request return URL. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setReturnUrl($value) { return $this->setParameter('returnUrl', $value); } /** * Get the request cancel URL. * * @return string */ public function getCancelUrl() { return $this->getParameter('cancelUrl'); } /** * Sets the request cancel URL. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setCancelUrl($value) { return $this->setParameter('cancelUrl', $value); } /** * Get the request notify URL. * * @return string */ public function getNotifyUrl() { return $this->getParameter('notifyUrl'); } /** * Sets the request notify URL. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setNotifyUrl($value) { return $this->setParameter('notifyUrl', $value); } /** * Get the payment issuer. * * This field is used by some European gateways, and normally represents * the bank where an account is held (separate from the card brand). * * @return string */ public function getIssuer() { return $this->getParameter('issuer'); } /** * Set the payment issuer. * * This field is used by some European gateways, and normally represents * the bank where an account is held (separate from the card brand). * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setIssuer($value) { return $this->setParameter('issuer', $value); } /** * Get the payment issuer. * * This field is used by some European gateways, which support * multiple payment providers with a single API. * * @return string */ public function getPaymentMethod() { return $this->getParameter('paymentMethod'); } /** * Set the payment method. * * This field is used by some European gateways, which support * multiple payment providers with a single API. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setPaymentMethod($value) { return $this->setParameter('paymentMethod', $value); } public function send() { $data = $this->getData(); return $this->sendData($data); } public function getResponse() { if (null === $this->response) { throw new RuntimeException('You must call send() before accessing the Response!'); } return $this->response; } } src/Omnipay/Common/Message/ResponseInterface.php 0000604 00000002507 15174372523 0015724 0 ustar 00 <?php /** * Response interface */ namespace Omnipay\Common\Message; /** * Response Interface * * This interface class defines the standard functions that any Omnipay response * interface needs to be able to provide. It is an extension of MessageInterface. * * @see MessageInterface */ interface ResponseInterface extends MessageInterface { /** * Get the original request which generated this response * * @return RequestInterface */ public function getRequest(); /** * Is the response successful? * * @return boolean */ public function isSuccessful(); /** * Does the response require a redirect? * * @return boolean */ public function isRedirect(); /** * Is the transaction cancelled by the user? * * @return boolean */ public function isCancelled(); /** * Response Message * * @return string A response message from the payment gateway */ public function getMessage(); /** * Response code * * @return string A response code from the payment gateway */ public function getCode(); /** * Gateway Reference * * @return string A reference provided by the gateway to represent this transaction */ public function getTransactionReference(); } src/Omnipay/Common/Message/RequestInterface.php 0000604 00000002033 15174372523 0015550 0 ustar 00 <?php /** * Request Interface */ namespace Omnipay\Common\Message; /** * Request Interface * * This interface class defines the standard functions that any Omnipay request * interface needs to be able to provide. It is an extension of MessageInterface. * * @see MessageInterface */ interface RequestInterface extends MessageInterface { /** * Initialize request with parameters */ public function initialize(array $parameters = array()); /** * Get all request parameters * * @return array */ public function getParameters(); /** * Get the response to this request (if the request has been sent) * * @return ResponseInterface */ public function getResponse(); /** * Send the request * * @return ResponseInterface */ public function send(); /** * Send the request with specified data * * @param mixed $data The data to send * @return ResponseInterface */ public function sendData($data); } src/Omnipay/Common/Message/FetchIssuersResponseInterface.php 0000604 00000001460 15174372523 0020251 0 ustar 00 <?php /** * Fetch Issuers Response interface */ namespace Omnipay\Common\Message; /** * Fetch Issuers Response interface * * This interface class defines the functionality of a response * that is a "fetch issuers" response. It extends the ResponseInterface * interface class with some extra functions relating to the * specifics of a response to fetch the issuers from the gateway. * This happens when the gateway needs the customer to choose a * card issuer. * * @see ResponseInterface * @see Omnipay\Common\Issuer */ interface FetchIssuersResponseInterface extends ResponseInterface { /** * Get the returned list of issuers. * * These represent banks which the user must choose between. * * @return \Omnipay\Common\Issuer[] */ public function getIssuers(); } src/Omnipay/Common/Message/AbstractResponse.php 0000604 00000007770 15174372523 0015576 0 ustar 00 <?php /** * Abstract Response */ namespace Omnipay\Common\Message; use Omnipay\Common\Exception\RuntimeException; use Symfony\Component\HttpFoundation\RedirectResponse as HttpRedirectResponse; use Symfony\Component\HttpFoundation\Response as HttpResponse; /** * Abstract Response * * This abstract class implements ResponseInterface and defines a basic * set of functions that all Omnipay Requests are intended to include. * * Objects of this class or a subclass are usually created in the Request * object (subclass of AbstractRequest) as the return parameters from the * send() function. * * Example -- validating and sending a request: * * <code> * $myResponse = $myRequest->send(); * // now do something with the $myResponse object, test for success, etc. * </code> * * @see ResponseInterface */ abstract class AbstractResponse implements ResponseInterface { /** * The embodied request object. * * @var RequestInterface */ protected $request; /** * The data contained in the response. * * @var mixed */ protected $data; /** * Constructor * * @param RequestInterface $request the initiating request. * @param mixed $data */ public function __construct(RequestInterface $request, $data) { $this->request = $request; $this->data = $data; } /** * Get the initiating request object. * * @return RequestInterface */ public function getRequest() { return $this->request; } public function isRedirect() { return false; } public function isTransparentRedirect() { return false; } public function isCancelled() { return false; } /** * Get the response data. * * @return mixed */ public function getData() { return $this->data; } public function getMessage() { return null; } public function getCode() { return null; } public function getTransactionReference() { return null; } /** * Automatically perform any required redirect * * This method is meant to be a helper for simple scenarios. If you want to customize the * redirection page, just call the getRedirectUrl() and getRedirectData() methods directly. * * @codeCoverageIgnore */ public function redirect() { $this->getRedirectResponse()->send(); exit; } public function getRedirectResponse() { if (!$this instanceof RedirectResponseInterface || !$this->isRedirect()) { throw new RuntimeException('This response does not support redirection.'); } if ('GET' === $this->getRedirectMethod()) { return HttpRedirectResponse::create($this->getRedirectUrl()); } elseif ('POST' === $this->getRedirectMethod()) { $hiddenFields = ''; foreach ($this->getRedirectData() as $key => $value) { $hiddenFields .= sprintf( '<input type="hidden" name="%1$s" value="%2$s" />', htmlentities($key, ENT_QUOTES, 'UTF-8', false), htmlentities($value, ENT_QUOTES, 'UTF-8', false) )."\n"; } $output = '<!DOCTYPE html> <html> <head> <title>Redirecting...</title> </head> <body onload="document.forms[0].submit();"> <form action="%1$s" method="post"> <p>Redirecting to payment page...</p> <p> %2$s <input type="submit" value="Continue" /> </p> </form> </body> </html>'; $output = sprintf( $output, htmlentities($this->getRedirectUrl(), ENT_QUOTES, 'UTF-8', false), $hiddenFields ); return HttpResponse::create($output); } throw new RuntimeException('Invalid redirect method "'.$this->getRedirectMethod().'".'); } } src/Omnipay/Common/Message/RedirectResponseInterface.php 0000604 00000001573 15174372523 0017410 0 ustar 00 <?php /** * Redirect Response interface */ namespace Omnipay\Common\Message; /** * Redirect Response interface * * This interface class defines the functionality of a response * that is a redirect response. It extends the ResponseInterface * interface class with some extra functions relating to the * specifics of a redirect response from the gateway. * * @see ResponseInterface */ interface RedirectResponseInterface extends ResponseInterface { /** * Gets the redirect target url. */ public function getRedirectUrl(); /** * Get the required redirect method (either GET or POST). */ public function getRedirectMethod(); /** * Gets the redirect form data array, if the redirect method is POST. */ public function getRedirectData(); /** * Perform the required redirect. */ public function redirect(); } src/Omnipay/Common/GatewayInterface.php 0000604 00000002321 15174372523 0014135 0 ustar 00 <?php /** * Payment gateway interface */ namespace Omnipay\Common; /** * Payment gateway interface * * This interface class defines the standard functions that any * Omnipay gateway needs to define. * * @see AbstractGateway */ interface GatewayInterface { /** * Get gateway display name * * This can be used by carts to get the display name for each gateway. */ public function getName(); /** * Get gateway short name * * This name can be used with GatewayFactory as an alias of the gateway class, * to create new instances of this gateway. */ public function getShortName(); /** * Define gateway parameters, in the following format: * * array( * 'username' => '', // string variable * 'testMode' => false, // boolean variable * 'landingPage' => array('billing', 'login'), // enum variable, first item is default * ); */ public function getDefaultParameters(); /** * Initialize gateway with parameters */ public function initialize(array $parameters = array()); /** * Get all gateway parameters * * @return array */ public function getParameters(); } src/Omnipay/Common/CreditCard.php 0000604 00000076556 15174372523 0012744 0 ustar 00 <?php /** * Credit Card class */ namespace Omnipay\Common; use DateTime; use DateTimeZone; use Omnipay\Common\Exception\InvalidCreditCardException; use Symfony\Component\HttpFoundation\ParameterBag; /** * Credit Card class * * This class defines and abstracts all of the credit card types used * throughout the Omnipay system. * * Example: * * <code> * // Define credit card parameters, which should look like this * $parameters = [ * 'firstName' => 'Bobby', * 'lastName' => 'Tables', * 'number' => '4444333322221111', * 'cvv' => '123', * 'expiryMonth' => '12', * 'expiryYear' => '2017', * 'email' => 'testcard@gmail.com', * ]; * * // Create a credit card object * $card = new CreditCard($parameters); * </code> * * The full list of card attributes that may be set via the parameter to * *new* is as follows: * * * title * * firstName * * lastName * * name * * company * * address1 * * address2 * * city * * postcode * * state * * country * * phone * * fax * * number * * expiryMonth * * expiryYear * * startMonth * * startYear * * cvv * * issueNumber * * billingTitle * * billingName * * billingFirstName * * billingLastName * * billingCompany * * billingAddress1 * * billingAddress2 * * billingCity * * billingPostcode * * billingState * * billingCountry * * billingPhone * * billingFax * * shippingTitle * * shippingName * * shippingFirstName * * shippingLastName * * shippingCompany * * shippingAddress1 * * shippingAddress2 * * shippingCity * * shippingPostcode * * shippingState * * shippingCountry * * shippingPhone * * shippingFax * * email * * birthday * * gender * * If any unknown parameters are passed in, they will be ignored. No error is thrown. */ class CreditCard { const BRAND_VISA = 'visa'; const BRAND_MASTERCARD = 'mastercard'; const BRAND_DISCOVER = 'discover'; const BRAND_AMEX = 'amex'; const BRAND_DINERS_CLUB = 'diners_club'; const BRAND_JCB = 'jcb'; const BRAND_SWITCH = 'switch'; const BRAND_SOLO = 'solo'; const BRAND_DANKORT = 'dankort'; const BRAND_MAESTRO = 'maestro'; const BRAND_FORBRUGSFORENINGEN = 'forbrugsforeningen'; const BRAND_LASER = 'laser'; /** * Internal storage of all of the card parameters. * * @var \Symfony\Component\HttpFoundation\ParameterBag */ protected $parameters; /** * Create a new CreditCard object using the specified parameters * * @param array $parameters An array of parameters to set on the new object */ public function __construct($parameters = null) { $this->initialize($parameters); } /** * All known/supported card brands, and a regular expression to match them. * * The order of the card brands is important, as some of the regular expressions overlap. * * Note: The fact that this class knows about a particular card brand does not imply * that your gateway supports it. * * @return array * @link https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb */ public function getSupportedBrands() { return array( static::BRAND_VISA => '/^4\d{12}(\d{3})?$/', static::BRAND_MASTERCARD => '/^(5[1-5]\d{4}|677189)\d{10}$/', static::BRAND_DISCOVER => '/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/', static::BRAND_AMEX => '/^3[47]\d{13}$/', static::BRAND_DINERS_CLUB => '/^3(0[0-5]|[68]\d)\d{11}$/', static::BRAND_JCB => '/^35(28|29|[3-8]\d)\d{12}$/', static::BRAND_SWITCH => '/^6759\d{12}(\d{2,3})?$/', static::BRAND_SOLO => '/^6767\d{12}(\d{2,3})?$/', static::BRAND_DANKORT => '/^5019\d{12}$/', static::BRAND_MAESTRO => '/^(5[06-8]|6\d)\d{10,17}$/', static::BRAND_FORBRUGSFORENINGEN => '/^600722\d{10}$/', static::BRAND_LASER => '/^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/', ); } /** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array $parameters An associative array of parameters * @return CreditCard provides a fluent interface. */ public function initialize($parameters = null) { $this->parameters = new ParameterBag; Helper::initialize($this, $parameters); return $this; } /** * Get all parameters. * * @return array An associative array of parameters. */ public function getParameters() { return $this->parameters->all(); } /** * Get one parameter. * * @return mixed A single parameter value. */ protected function getParameter($key) { return $this->parameters->get($key); } /** * Set one parameter. * * @param string $key Parameter key * @param mixed $value Parameter value * @return CreditCard provides a fluent interface. */ protected function setParameter($key, $value) { $this->parameters->set($key, $value); return $this; } /** * Set the credit card year. * * The input value is normalised to a 4 digit number. * * @param string $key Parameter key, e.g. 'expiryYear' * @param mixed $value Parameter value * @return CreditCard provides a fluent interface. */ protected function setYearParameter($key, $value) { // normalize year to four digits if (null === $value || '' === $value) { $value = null; } else { $value = (int) gmdate('Y', gmmktime(0, 0, 0, 1, 1, (int) $value)); } return $this->setParameter($key, $value); } /** * Validate this credit card. If the card is invalid, InvalidCreditCardException is thrown. * * This method is called internally by gateways to avoid wasting time with an API call * when the credit card is clearly invalid. * * Generally if you want to validate the credit card yourself with custom error * messages, you should use your framework's validation library, not this method. * * @return void */ public function validate() { foreach (array('number', 'expiryMonth', 'expiryYear') as $key) { if (!$this->getParameter($key)) { throw new InvalidCreditCardException("The $key parameter is required"); } } if ($this->getExpiryDate('Ym') < gmdate('Ym')) { throw new InvalidCreditCardException('Card has expired'); } if (!Helper::validateLuhn($this->getNumber())) { throw new InvalidCreditCardException('Card number is invalid'); } if (!is_null($this->getNumber()) && !preg_match('/^\d{12,19}$/i', $this->getNumber())) { throw new InvalidCreditCardException('Card number should have 12 to 19 digits'); } } /** * Get Card Title. * * @return string */ public function getTitle() { return $this->getBillingTitle(); } /** * Set Card Title. * * @param string $value Parameter value * @return CreditCard provides a fluent interface. */ public function setTitle($value) { $this->setBillingTitle($value); $this->setShippingTitle($value); return $this; } /** * Get Card First Name. * * @return string */ public function getFirstName() { return $this->getBillingFirstName(); } /** * Set Card First Name (Billing and Shipping). * * @param string $value Parameter value * @return CreditCard provides a fluent interface. */ public function setFirstName($value) { $this->setBillingFirstName($value); $this->setShippingFirstName($value); return $this; } /** * Get Card Last Name. * * @return string */ public function getLastName() { return $this->getBillingLastName(); } /** * Set Card Last Name (Billing and Shipping). * * @param string $value Parameter value * @return CreditCard provides a fluent interface. */ public function setLastName($value) { $this->setBillingLastName($value); $this->setShippingLastName($value); return $this; } /** * Get Card Name. * * @return string */ public function getName() { return $this->getBillingName(); } /** * Set Card Name (Billing and Shipping). * * @param string $value Parameter value * @return CreditCard provides a fluent interface. */ public function setName($value) { $this->setBillingName($value); $this->setShippingName($value); return $this; } /** * Get Card Number. * * @return string */ public function getNumber() { return $this->getParameter('number'); } /** * Set Card Number * * Non-numeric characters are stripped out of the card number, so * it's safe to pass in strings such as "4444-3333 2222 1111" etc. * * @param string $value Parameter value * @return CreditCard provides a fluent interface. */ public function setNumber($value) { // strip non-numeric characters return $this->setParameter('number', preg_replace('/\D/', '', $value)); } /** * Get the last 4 digits of the card number. * * @return string */ public function getNumberLastFour() { return substr($this->getNumber(), -4, 4) ?: null; } /** * Returns a masked credit card number with only the last 4 chars visible * * @param string $mask Character to use in place of numbers * @return string */ public function getNumberMasked($mask = 'X') { $maskLength = strlen($this->getNumber()) - 4; return str_repeat($mask, $maskLength) . $this->getNumberLastFour(); } /** * Credit Card Brand * * Iterates through known/supported card brands to determine the brand of this card * * @return string */ public function getBrand() { foreach ($this->getSupportedBrands() as $brand => $val) { if (preg_match($val, $this->getNumber())) { return $brand; } } } /** * Get the card expiry month. * * @return string */ public function getExpiryMonth() { return $this->getParameter('expiryMonth'); } /** * Sets the card expiry month. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setExpiryMonth($value) { return $this->setParameter('expiryMonth', (int) $value); } /** * Get the card expiry year. * * @return string */ public function getExpiryYear() { return $this->getParameter('expiryYear'); } /** * Sets the card expiry year. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setExpiryYear($value) { return $this->setYearParameter('expiryYear', $value); } /** * Get the card expiry date, using the specified date format string. * * @param string $format * * @return string */ public function getExpiryDate($format) { return gmdate($format, gmmktime(0, 0, 0, $this->getExpiryMonth(), 1, $this->getExpiryYear())); } /** * Get the card start month. * * @return string */ public function getStartMonth() { return $this->getParameter('startMonth'); } /** * Sets the card start month. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setStartMonth($value) { return $this->setParameter('startMonth', (int) $value); } /** * Get the card start year. * * @return string */ public function getStartYear() { return $this->getParameter('startYear'); } /** * Sets the card start year. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setStartYear($value) { return $this->setYearParameter('startYear', $value); } /** * Get the card start date, using the specified date format string * * @param string $format * * @return string */ public function getStartDate($format) { return gmdate($format, gmmktime(0, 0, 0, $this->getStartMonth(), 1, $this->getStartYear())); } /** * Get the card CVV. * * @return string */ public function getCvv() { return $this->getParameter('cvv'); } /** * Sets the card CVV. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setCvv($value) { return $this->setParameter('cvv', $value); } /** * Get the card issue number. * * @return string */ public function getIssueNumber() { return $this->getParameter('issueNumber'); } /** * Sets the card issue number. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setIssueNumber($value) { return $this->setParameter('issueNumber', $value); } /** * Get the card billing title. * * @return string */ public function getBillingTitle() { return $this->getParameter('billingTitle'); } /** * Sets the card billing title. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingTitle($value) { return $this->setParameter('billingTitle', $value); } /** * Get the card billing name. * * @return string */ public function getBillingName() { return trim($this->getBillingFirstName() . ' ' . $this->getBillingLastName()); } /** * Sets the card billing name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingName($value) { $names = explode(' ', $value, 2); $this->setBillingFirstName($names[0]); $this->setBillingLastName(isset($names[1]) ? $names[1] : null); return $this; } /** * Get the first part of the card billing name. * * @return string */ public function getBillingFirstName() { return $this->getParameter('billingFirstName'); } /** * Sets the first part of the card billing name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingFirstName($value) { return $this->setParameter('billingFirstName', $value); } /** * Get the last part of the card billing name. * * @return string */ public function getBillingLastName() { return $this->getParameter('billingLastName'); } /** * Sets the last part of the card billing name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingLastName($value) { return $this->setParameter('billingLastName', $value); } /** * Get the billing company name. * * @return string */ public function getBillingCompany() { return $this->getParameter('billingCompany'); } /** * Sets the billing company name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingCompany($value) { return $this->setParameter('billingCompany', $value); } /** * Get the billing address, line 1. * * @return string */ public function getBillingAddress1() { return $this->getParameter('billingAddress1'); } /** * Sets the billing address, line 1. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingAddress1($value) { return $this->setParameter('billingAddress1', $value); } /** * Get the billing address, line 2. * * @return string */ public function getBillingAddress2() { return $this->getParameter('billingAddress2'); } /** * Sets the billing address, line 2. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingAddress2($value) { return $this->setParameter('billingAddress2', $value); } /** * Get the billing city. * * @return string */ public function getBillingCity() { return $this->getParameter('billingCity'); } /** * Sets billing city. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingCity($value) { return $this->setParameter('billingCity', $value); } /** * Get the billing postcode. * * @return string */ public function getBillingPostcode() { return $this->getParameter('billingPostcode'); } /** * Sets the billing postcode. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingPostcode($value) { return $this->setParameter('billingPostcode', $value); } /** * Get the billing state. * * @return string */ public function getBillingState() { return $this->getParameter('billingState'); } /** * Sets the billing state. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingState($value) { return $this->setParameter('billingState', $value); } /** * Get the billing country name. * * @return string */ public function getBillingCountry() { return $this->getParameter('billingCountry'); } /** * Sets the billing country name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingCountry($value) { return $this->setParameter('billingCountry', $value); } /** * Get the billing phone number. * * @return string */ public function getBillingPhone() { return $this->getParameter('billingPhone'); } /** * Sets the billing phone number. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingPhone($value) { return $this->setParameter('billingPhone', $value); } /** * Get the billing fax number. * * @return string */ public function getBillingFax() { return $this->getParameter('billingFax'); } /** * Sets the billing fax number. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBillingFax($value) { return $this->setParameter('billingFax', $value); } /** * Get the title of the card shipping name. * * @return string */ public function getShippingTitle() { return $this->getParameter('shippingTitle'); } /** * Sets the title of the card shipping name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingTitle($value) { return $this->setParameter('shippingTitle', $value); } /** * Get the card shipping name. * * @return string */ public function getShippingName() { return trim($this->getShippingFirstName() . ' ' . $this->getShippingLastName()); } /** * Sets the card shipping name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingName($value) { $names = explode(' ', $value, 2); $this->setShippingFirstName($names[0]); $this->setShippingLastName(isset($names[1]) ? $names[1] : null); return $this; } /** * Get the first part of the card shipping name. * * @return string */ public function getShippingFirstName() { return $this->getParameter('shippingFirstName'); } /** * Sets the first part of the card shipping name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingFirstName($value) { return $this->setParameter('shippingFirstName', $value); } /** * Get the last part of the card shipping name. * * @return string */ public function getShippingLastName() { return $this->getParameter('shippingLastName'); } /** * Sets the last part of the card shipping name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingLastName($value) { return $this->setParameter('shippingLastName', $value); } /** * Get the shipping company name. * * @return string */ public function getShippingCompany() { return $this->getParameter('shippingCompany'); } /** * Sets the shipping company name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingCompany($value) { return $this->setParameter('shippingCompany', $value); } /** * Get the shipping address, line 1. * * @return string */ public function getShippingAddress1() { return $this->getParameter('shippingAddress1'); } /** * Sets the shipping address, line 1. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingAddress1($value) { return $this->setParameter('shippingAddress1', $value); } /** * Get the shipping address, line 2. * * @return string */ public function getShippingAddress2() { return $this->getParameter('shippingAddress2'); } /** * Sets the shipping address, line 2. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingAddress2($value) { return $this->setParameter('shippingAddress2', $value); } /** * Get the shipping city. * * @return string */ public function getShippingCity() { return $this->getParameter('shippingCity'); } /** * Sets the shipping city. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingCity($value) { return $this->setParameter('shippingCity', $value); } /** * Get the shipping postcode. * * @return string */ public function getShippingPostcode() { return $this->getParameter('shippingPostcode'); } /** * Sets the shipping postcode. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingPostcode($value) { return $this->setParameter('shippingPostcode', $value); } /** * Get the shipping state. * * @return string */ public function getShippingState() { return $this->getParameter('shippingState'); } /** * Sets the shipping state. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingState($value) { return $this->setParameter('shippingState', $value); } /** * Get the shipping country. * * @return string */ public function getShippingCountry() { return $this->getParameter('shippingCountry'); } /** * Sets the shipping country. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingCountry($value) { return $this->setParameter('shippingCountry', $value); } /** * Get the shipping phone number. * * @return string */ public function getShippingPhone() { return $this->getParameter('shippingPhone'); } /** * Sets the shipping phone number. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingPhone($value) { return $this->setParameter('shippingPhone', $value); } /** * Get the shipping fax number. * * @return string */ public function getShippingFax() { return $this->getParameter('shippingFax'); } /** * Sets the shipping fax number. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setShippingFax($value) { return $this->setParameter('shippingFax', $value); } /** * Get the billing address, line 1. * * @return string */ public function getAddress1() { return $this->getParameter('billingAddress1'); } /** * Sets the billing and shipping address, line 1. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setAddress1($value) { $this->setParameter('billingAddress1', $value); $this->setParameter('shippingAddress1', $value); return $this; } /** * Get the billing address, line 2. * * @return string */ public function getAddress2() { return $this->getParameter('billingAddress2'); } /** * Sets the billing and shipping address, line 2. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setAddress2($value) { $this->setParameter('billingAddress2', $value); $this->setParameter('shippingAddress2', $value); return $this; } /** * Get the billing city. * * @return string */ public function getCity() { return $this->getParameter('billingCity'); } /** * Sets the billing and shipping city. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setCity($value) { $this->setParameter('billingCity', $value); $this->setParameter('shippingCity', $value); return $this; } /** * Get the billing postcode. * * @return string */ public function getPostcode() { return $this->getParameter('billingPostcode'); } /** * Sets the billing and shipping postcode. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setPostcode($value) { $this->setParameter('billingPostcode', $value); $this->setParameter('shippingPostcode', $value); return $this; } /** * Get the billing state. * * @return string */ public function getState() { return $this->getParameter('billingState'); } /** * Sets the billing and shipping state. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setState($value) { $this->setParameter('billingState', $value); $this->setParameter('shippingState', $value); return $this; } /** * Get the billing country. * * @return string */ public function getCountry() { return $this->getParameter('billingCountry'); } /** * Sets the billing and shipping country. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setCountry($value) { $this->setParameter('billingCountry', $value); $this->setParameter('shippingCountry', $value); return $this; } /** * Get the billing phone number. * * @return string */ public function getPhone() { return $this->getParameter('billingPhone'); } /** * Sets the billing and shipping phone number. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setPhone($value) { $this->setParameter('billingPhone', $value); $this->setParameter('shippingPhone', $value); return $this; } /** * Get the billing fax number.. * * @return string */ public function getFax() { return $this->getParameter('billingFax'); } /** * Sets the billing and shipping fax number. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setFax($value) { $this->setParameter('billingFax', $value); $this->setParameter('shippingFax', $value); return $this; } /** * Get the card billing company name. * * @return string */ public function getCompany() { return $this->getParameter('billingCompany'); } /** * Sets the billing and shipping company name. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setCompany($value) { $this->setParameter('billingCompany', $value); $this->setParameter('shippingCompany', $value); return $this; } /** * Get the cardholder's email address. * * @return string */ public function getEmail() { return $this->getParameter('email'); } /** * Sets the cardholder's email address. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setEmail($value) { return $this->setParameter('email', $value); } /** * Get the cardholder's birthday. * * @return string */ public function getBirthday($format = 'Y-m-d') { $value = $this->getParameter('birthday'); return $value ? $value->format($format) : null; } /** * Sets the cardholder's birthday. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setBirthday($value) { if ($value) { $value = new DateTime($value, new DateTimeZone('UTC')); } else { $value = null; } return $this->setParameter('birthday', $value); } /** * Get the cardholder's gender. * * @return string */ public function getGender() { return $this->getParameter('gender'); } /** * Sets the cardholder's gender. * * @param string $value * @return CreditCard provides a fluent interface. */ public function setGender($value) { return $this->setParameter('gender', $value); } } src/Omnipay/Common/Currency.php 0000604 00000011346 15174372523 0012514 0 ustar 00 <?php /** * Currency class */ namespace Omnipay\Common; /** * Currency class * * This class abstracts certain functionality around currency objects, * currency codes and currency numbers relating to global currencies used * in the Omnipay system. */ class Currency { private $code; private $numeric; private $decimals; /** * Create a new Currency object */ private function __construct($code, $numeric, $decimals) { $this->code = $code; $this->numeric = $numeric; $this->decimals = $decimals; } /** * Get the three letter code for the currency * * @return string */ public function getCode() { return $this->code; } /** * Get the numeric code for this currency * * @return string */ public function getNumeric() { return $this->numeric; } /** * Get the number of decimal places for this currency * * @return int */ public function getDecimals() { return $this->decimals; } /** * Find a specific currency * * @param string $code The three letter currency code * @return mixed A Currency object, or null if no currency was found */ public static function find($code) { $code = strtoupper($code); $currencies = static::all(); if (isset($currencies[$code])) { return new static($code, $currencies[$code]['numeric'], $currencies[$code]['decimals']); } } /** * Get an array of all supported currencies * * @return array */ public static function all() { return array( 'ARS' => array('numeric' => '032', 'decimals' => 2), 'AUD' => array('numeric' => '036', 'decimals' => 2), 'BOB' => array('numeric' => '068', 'decimals' => 2), 'BRL' => array('numeric' => '986', 'decimals' => 2), 'BTC' => array('numeric' => null, 'decimals' => 8), 'CAD' => array('numeric' => '124', 'decimals' => 2), 'CHF' => array('numeric' => '756', 'decimals' => 2), 'CLP' => array('numeric' => '152', 'decimals' => 0), 'CNY' => array('numeric' => '156', 'decimals' => 2), 'COP' => array('numeric' => '170', 'decimals' => 2), 'CRC' => array('numeric' => '188', 'decimals' => 2), 'CZK' => array('numeric' => '203', 'decimals' => 2), 'DKK' => array('numeric' => '208', 'decimals' => 2), 'DOP' => array('numeric' => '214', 'decimals' => 2), 'EUR' => array('numeric' => '978', 'decimals' => 2), 'FJD' => array('numeric' => '242', 'decimals' => 2), 'GBP' => array('numeric' => '826', 'decimals' => 2), 'GTQ' => array('numeric' => '320', 'decimals' => 2), 'HKD' => array('numeric' => '344', 'decimals' => 2), 'HUF' => array('numeric' => '348', 'decimals' => 2), 'ILS' => array('numeric' => '376', 'decimals' => 2), 'INR' => array('numeric' => '356', 'decimals' => 2), 'JPY' => array('numeric' => '392', 'decimals' => 0), 'KRW' => array('numeric' => '410', 'decimals' => 0), 'LAK' => array('numeric' => '418', 'decimals' => 0), 'MXN' => array('numeric' => '484', 'decimals' => 2), 'MYR' => array('numeric' => '458', 'decimals' => 2), 'NOK' => array('numeric' => '578', 'decimals' => 2), 'NZD' => array('numeric' => '554', 'decimals' => 2), 'PEN' => array('numeric' => '604', 'decimals' => 2), 'PGK' => array('numeric' => '598', 'decimals' => 2), 'PHP' => array('numeric' => '608', 'decimals' => 2), 'PLN' => array('numeric' => '985', 'decimals' => 2), 'PYG' => array('numeric' => '600', 'decimals' => 0), 'SBD' => array('numeric' => '090', 'decimals' => 2), 'SEK' => array('numeric' => '752', 'decimals' => 2), 'SGD' => array('numeric' => '702', 'decimals' => 2), 'THB' => array('numeric' => '764', 'decimals' => 2), 'TOP' => array('numeric' => '776', 'decimals' => 2), 'TRY' => array('numeric' => '949', 'decimals' => 2), 'TWD' => array('numeric' => '901', 'decimals' => 2), 'USD' => array('numeric' => '840', 'decimals' => 2), 'UYU' => array('numeric' => '858', 'decimals' => 2), 'VEF' => array('numeric' => '937', 'decimals' => 2), 'VND' => array('numeric' => '704', 'decimals' => 0), 'VUV' => array('numeric' => '548', 'decimals' => 0), 'WST' => array('numeric' => '882', 'decimals' => 2), 'ZAR' => array('numeric' => '710', 'decimals' => 2), ); } } src/Omnipay/Common/Item.php 0000604 00000004565 15174372523 0011625 0 ustar 00 <?php /** * Cart Item */ namespace Omnipay\Common; use Symfony\Component\HttpFoundation\ParameterBag; /** * Cart Item * * This class defines a single cart item in the Omnipay system. * * @see ItemInterface */ class Item implements ItemInterface { /** * @var \Symfony\Component\HttpFoundation\ParameterBag */ protected $parameters; /** * Create a new item with the specified parameters * * @param array|null $parameters An array of parameters to set on the new object */ public function __construct($parameters = null) { $this->initialize($parameters); } /** * Initialize this item with the specified parameters * * @param array|null $parameters An array of parameters to set on this object */ public function initialize($parameters = null) { $this->parameters = new ParameterBag; Helper::initialize($this, $parameters); return $this; } public function getParameters() { return $this->parameters->all(); } protected function getParameter($key) { return $this->parameters->get($key); } protected function setParameter($key, $value) { $this->parameters->set($key, $value); return $this; } /** * {@inheritDoc} */ public function getName() { return $this->getParameter('name'); } /** * Set the item name */ public function setName($value) { return $this->setParameter('name', $value); } /** * {@inheritDoc} */ public function getDescription() { return $this->getParameter('description'); } /** * Set the item description */ public function setDescription($value) { return $this->setParameter('description', $value); } /** * {@inheritDoc} */ public function getQuantity() { return $this->getParameter('quantity'); } /** * Set the item quantity */ public function setQuantity($value) { return $this->setParameter('quantity', $value); } /** * {@inheritDoc} */ public function getPrice() { return $this->getParameter('price'); } /** * Set the item price */ public function setPrice($value) { return $this->setParameter('price', $value); } } src/Omnipay/Common/Helper.php 0000604 00000006667 15174372523 0012153 0 ustar 00 <?php /** * Helper class */ namespace Omnipay\Common; /** * Helper class * * This class defines various static utility functions that are in use * throughout the Omnipay system. */ class Helper { /** * Convert a string to camelCase. Strings already in camelCase will not be harmed. * * @param string $str The input string * @return string camelCased output string */ public static function camelCase($str) { return preg_replace_callback( '/_([a-z])/', function ($match) { return strtoupper($match[1]); }, $str ); } /** * Validate a card number according to the Luhn algorithm. * * @param string $number The card number to validate * @return boolean True if the supplied card number is valid */ public static function validateLuhn($number) { $str = ''; foreach (array_reverse(str_split($number)) as $i => $c) { $str .= $i % 2 ? $c * 2 : $c; } return array_sum(str_split($str)) % 10 === 0; } /** * Initialize an object with a given array of parameters * * Parameters are automatically converted to camelCase. Any parameters which do * not match a setter on the target object are ignored. * * @param mixed $target The object to set parameters on * @param array $parameters An array of parameters to set */ public static function initialize($target, $parameters) { if (is_array($parameters)) { foreach ($parameters as $key => $value) { $method = 'set'.ucfirst(static::camelCase($key)); if (method_exists($target, $method)) { $target->$method($value); } } } } /** * Resolve a gateway class to a short name. * * The short name can be used with GatewayFactory as an alias of the gateway class, * to create new instances of a gateway. */ public static function getGatewayShortName($className) { if (0 === strpos($className, '\\')) { $className = substr($className, 1); } if (0 === strpos($className, 'Omnipay\\')) { return trim(str_replace('\\', '_', substr($className, 8, -7)), '_'); } return '\\'.$className; } /** * Resolve a short gateway name to a full namespaced gateway class. * * Class names beginning with a namespace marker (\) are left intact. * Non-namespaced classes are expected to be in the \Omnipay namespace, e.g.: * * \Custom\Gateway => \Custom\Gateway * \Custom_Gateway => \Custom_Gateway * Stripe => \Omnipay\Stripe\Gateway * PayPal\Express => \Omnipay\PayPal\ExpressGateway * PayPal_Express => \Omnipay\PayPal\ExpressGateway * * @param string $shortName The short gateway name * @return string The fully namespaced gateway class name */ public static function getGatewayClassName($shortName) { if (0 === strpos($shortName, '\\')) { return $shortName; } // replace underscores with namespace marker, PSR-0 style $shortName = str_replace('_', '\\', $shortName); if (false === strpos($shortName, '\\')) { $shortName .= '\\'; } return '\\Omnipay\\'.$shortName.'Gateway'; } } src/Omnipay/Common/GatewayFactory.php 0000604 00000006027 15174372523 0013653 0 ustar 00 <?php /** * Omnipay Gateway Factory class */ namespace Omnipay\Common; use Guzzle\Http\ClientInterface; use Omnipay\Common\Exception\RuntimeException; use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Omnipay Gateway Factory class * * This class abstracts a set of gateways that can be independently * registered, accessed, and used. * * Note that static calls to the Omnipay class are routed to this class by * the static call router (__callStatic) in Omnipay. * * Example: * * <code> * // Create a gateway for the PayPal ExpressGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('ExpressGateway'); * </code> * * @see Omnipay\Omnipay */ class GatewayFactory { /** * Internal storage for all available gateways * * @var array */ private $gateways = array(); /** * All available gateways * * @return array An array of gateway names */ public function all() { return $this->gateways; } /** * Replace the list of available gateways * * @param array $gateways An array of gateway names */ public function replace(array $gateways) { $this->gateways = $gateways; } /** * Register a new gateway * * @param string $className Gateway name */ public function register($className) { if (!in_array($className, $this->gateways)) { $this->gateways[] = $className; } } /** * Automatically find and register all officially supported gateways * * @return array An array of gateway names */ public function find() { foreach ($this->getSupportedGateways() as $gateway) { $class = Helper::getGatewayClassName($gateway); if (class_exists($class)) { $this->register($gateway); } } ksort($this->gateways); return $this->all(); } /** * Create a new gateway instance * * @param string $class Gateway name * @param ClientInterface|null $httpClient A Guzzle HTTP Client implementation * @param HttpRequest|null $httpRequest A Symfony HTTP Request implementation * @throws RuntimeException If no such gateway is found * @return object An object of class $class is created and returned */ public function create($class, ClientInterface $httpClient = null, HttpRequest $httpRequest = null) { $class = Helper::getGatewayClassName($class); if (!class_exists($class)) { throw new RuntimeException("Class '$class' not found"); } return new $class($httpClient, $httpRequest); } /** * Get a list of supported gateways which may be available * * @return array */ public function getSupportedGateways() { $package = json_decode(file_get_contents(__DIR__.'/../../../composer.json'), true); return $package['extra']['gateways']; } } src/Omnipay/Omnipay.php 0000604 00000005015 15174372523 0011102 0 ustar 00 <?php /** * Omnipay class */ namespace Omnipay; use Omnipay\Common\GatewayFactory; /** * Omnipay class * * Provides static access to the gateway factory methods. This is the * recommended route for creation and establishment of payment gateway * objects via the standard GatewayFactory. * * Example: * * <code> * // Create a gateway for the PayPal ExpressGateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('ExpressGateway'); * * // Initialise the gateway * $gateway->initialize(...); * * // Get the gateway parameters. * $parameters = $gateway->getParameters(); * * // Create a credit card object * $card = new CreditCard(...); * * // Do an authorisation transaction on the gateway * if ($gateway->supportsAuthorize()) { * $gateway->authorize(...); * } else { * throw new \Exception('Gateway does not support authorize()'); * } * </code> * * For further code examples see the *omnipay-example* repository on github. * * @see Omnipay\Common\GatewayFactory */ class Omnipay { /** * Internal factory storage * * @var GatewayFactory */ private static $factory; /** * Get the gateway factory * * Creates a new empty GatewayFactory if none has been set previously. * * @return GatewayFactory A GatewayFactory instance */ public static function getFactory() { if (is_null(static::$factory)) { static::$factory = new GatewayFactory; } return static::$factory; } /** * Set the gateway factory * * @param GatewayFactory $factory A GatewayFactory instance */ public static function setFactory(GatewayFactory $factory = null) { static::$factory = $factory; } /** * Static function call router. * * All other function calls to the Omnipay class are routed to the * factory. e.g. Omnipay::getSupportedGateways(1, 2, 3, 4) is routed to the * factory's getSupportedGateways method and passed the parameters 1, 2, 3, 4. * * Example: * * <code> * // Create a gateway for the PayPal ExpressGateway * $gateway = Omnipay::create('ExpressGateway'); * </code> * * @see GatewayFactory * * @param mixed Parameters passed to the factory method. */ public static function __callStatic($method, $parameters) { $factory = static::getFactory(); return call_user_func_array(array($factory, $method), $parameters); } } composer.json 0000604 00000004754 15174372523 0007305 0 ustar 00 { "name": "omnipay/common", "type": "library", "description": "Common components for Omnipay payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payment", "purchase" ], "homepage": "https://github.com/thephpleague/omnipay-common", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-common/contributors" } ], "autoload": { "psr-0": { "Omnipay\\Common\\" : "src/" }, "classmap": ["src/Omnipay/Omnipay.php"] }, "require": { "php": ">=5.3.2", "guzzle/guzzle": "~3.9", "symfony/http-foundation": "~2.1" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" }, "gateways": [ "AuthorizeNet_AIM", "AuthorizeNet_SIM", "Buckaroo", "Buckaroo_Ideal", "Buckaroo_PayPal", "CardSave", "Coinbase", "Dummy", "Eway_Rapid", "FirstData_Connect", "GoCardless", "Manual", "Migs_ThreeParty", "Migs_TwoParty", "Mollie", "MultiSafepay", "Netaxept", "NetBanx", "PayFast", "Payflow_Pro", "PaymentExpress_PxPay", "PaymentExpress_PxPost", "PayPal_Express", "PayPal_Pro", "Pin", "SagePay_Direct", "SagePay_Server", "SecurePay_DirectPost", "Stripe", "TargetPay_Directebanking", "TargetPay_Ideal", "TargetPay_Mrcash", "TwoCheckout", "WorldPay", "Alipay Bank", "AliPay Dual Func", "Alipay Express", "Alipay Mobile Express", "Alipay Secured", "Alipay Wap Express", "Cybersource", "DataCash", "Ecopayz", "Neteller", "Pacnet", "PaymentSense", "Realex Remote", "SecPay (PayPoint.net)", "Sisow", "Skrill", "YandexMoney", "YandexMoneyIndividual" ] } } .gitignore 0000604 00000000117 15174372523 0006540 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml .directory reports/ documents/ phpunit.xml.dist 0000604 00000001512 15174372523 0007723 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false"> <testsuites> <testsuite name="Omnipay Test Suite"> <directory>./tests/</directory> </testsuite> </testsuites> <listeners> <listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" /> </listeners> <filter> <whitelist> <directory>./src</directory> </whitelist> </filter> </phpunit>
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings