Skip to content

Commit 6ca44f1

Browse files
committed
Add Stripe gateway store() and unstore() methods
1 parent c1a59b3 commit 6ca44f1

File tree

6 files changed

+93
-195
lines changed

6 files changed

+93
-195
lines changed

src/Omnipay/Common/AbstractGateway.php

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
namespace Omnipay\Common;
1313

14-
use ReflectionMethod;
1514
use Guzzle\Http\ClientInterface;
1615
use Guzzle\Http\Client as HttpClient;
17-
use Omnipay\Common\Exception\BadMethodCallException;
1816
use Symfony\Component\HttpFoundation\ParameterBag;
1917
use Symfony\Component\HttpFoundation\Request as HttpRequest;
2018

@@ -111,51 +109,14 @@ public function setCurrency($value)
111109
return $this->setParameter('currency', $value);
112110
}
113111

114-
public function authorize(array $parameters = array())
115-
{
116-
throw new BadMethodCallException;
117-
}
118-
119-
public function completeAuthorize(array $parameters = array())
120-
{
121-
throw new BadMethodCallException;
122-
}
123-
124-
public function capture(array $parameters = array())
125-
{
126-
throw new BadMethodCallException;
127-
}
128-
129-
public function purchase(array $parameters = array())
130-
{
131-
throw new BadMethodCallException;
132-
}
133-
134-
public function completePurchase(array $parameters = array())
135-
{
136-
throw new BadMethodCallException;
137-
}
138-
139-
public function refund(array $parameters = array())
140-
{
141-
throw new BadMethodCallException;
142-
}
143-
144-
public function void(array $parameters = array())
145-
{
146-
throw new BadMethodCallException;
147-
}
148-
149112
/**
150113
* Supports Authorize
151114
*
152115
* @return boolean True if this gateway supports the authorize() method
153116
*/
154117
public function supportsAuthorize()
155118
{
156-
$reflectionMethod = new ReflectionMethod($this, 'authorize');
157-
158-
return __CLASS__ !== $reflectionMethod->getDeclaringClass()->getName();
119+
return method_exists($this, 'authorize');
159120
}
160121

161122
/**
@@ -165,9 +126,7 @@ public function supportsAuthorize()
165126
*/
166127
public function supportsCapture()
167128
{
168-
$reflectionMethod = new ReflectionMethod($this, 'capture');
169-
170-
return __CLASS__ !== $reflectionMethod->getDeclaringClass()->getName();
129+
return method_exists($this, 'capture');
171130
}
172131

173132
/**
@@ -177,9 +136,7 @@ public function supportsCapture()
177136
*/
178137
public function supportsRefund()
179138
{
180-
$reflectionMethod = new ReflectionMethod($this, 'refund');
181-
182-
return __CLASS__ !== $reflectionMethod->getDeclaringClass()->getName();
139+
return method_exists($this, 'refund');
183140
}
184141

185142
/**
@@ -189,9 +146,27 @@ public function supportsRefund()
189146
*/
190147
public function supportsVoid()
191148
{
192-
$reflectionMethod = new ReflectionMethod($this, 'void');
149+
return method_exists($this, 'void');
150+
}
193151

194-
return __CLASS__ !== $reflectionMethod->getDeclaringClass()->getName();
152+
/**
153+
* Supports Store
154+
*
155+
* @return boolean True if this gateway supports the store() method
156+
*/
157+
public function supportsStore()
158+
{
159+
return method_exists($this, 'store');
160+
}
161+
162+
/**
163+
* Supports Unstore
164+
*
165+
* @return boolean True if this gateway supports the unstore() method
166+
*/
167+
public function supportsUnstore()
168+
{
169+
return method_exists($this, 'unstore');
195170
}
196171

197172
/**

src/Omnipay/Common/GatewayInterface.php

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -55,65 +55,11 @@ public function initialize(array $paramters = array());
5555
*/
5656
public function getParameters();
5757

58-
/**
59-
* Authorize a new payment.
60-
*
61-
* @param array An array of options
62-
* @return Omnipay\ResponseInterface
63-
*/
64-
public function authorize(array $parameters = array());
65-
66-
/**
67-
* Handle return from an off-site authorization request.
68-
*
69-
* @param array An array of options
70-
* @return Omnipay\ResponseInterface
71-
*/
72-
public function completeAuthorize(array $parameters = array());
73-
74-
/**
75-
* Capture an authorized payment.
76-
*
77-
* @param array An array of options
78-
* @return Omnipay\ResponseInterface
79-
*/
80-
public function capture(array $parameters = array());
81-
8258
/**
8359
* Create a new charge (combined authorize + capture).
8460
*
8561
* @param array An array of options
8662
* @return Omnipay\ResponseInterface
8763
*/
8864
public function purchase(array $parameters = array());
89-
90-
/**
91-
* Handle return from an off-site purchase request.
92-
*
93-
* @param array An array of options
94-
* @return Omnipay\ResponseInterface
95-
*/
96-
public function completePurchase(array $parameters = array());
97-
98-
/**
99-
* Refund an existing transaction.
100-
*
101-
* This will refund a transaction which has been already submitted for processing,
102-
* and generally may be called up to 30 days after submitting the transaction.
103-
*
104-
* @param array An array of options
105-
* @return Omnipay\ResponseInterface
106-
*/
107-
public function refund(array $parameters = array());
108-
109-
/**
110-
* Void an existing transaction.
111-
*
112-
* This will prevent a transaction from being submitted for processing,
113-
* and can generally only be called up to 24 hours after submitting the transaction.
114-
*
115-
* @param array An array of options
116-
* @return Omnipay\ResponseInterface
117-
*/
118-
public function void(array $parameters = array());
11965
}

src/Omnipay/Common/Message/AbstractRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ public function setCardToken($value)
151151
return $this->setParameter('cardToken', $value);
152152
}
153153

154+
public function getCardReference()
155+
{
156+
return $this->getParameter('cardReference');
157+
}
158+
159+
public function setCardReference($value)
160+
{
161+
return $this->setParameter('cardReference', $value);
162+
}
163+
154164
public function getAmount()
155165
{
156166
return $this->getParameter('amount');

tests/Omnipay/Common/AbstractGatewayTest.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,7 @@ class AbstractGatewayTest extends TestCase
1818
{
1919
public function setUp()
2020
{
21-
$this->gateway = m::mock("\Omnipay\Common\AbstractGateway[getName,getDefaultParameters,send]");
22-
}
23-
24-
/**
25-
* @expectedException \Omnipay\Common\Exception\BadMethodCallException
26-
*/
27-
public function testAuthorize()
28-
{
29-
$this->gateway->authorize(array());
30-
}
31-
32-
/**
33-
* @expectedException \Omnipay\Common\Exception\BadMethodCallException
34-
*/
35-
public function testCompleteAuthorize()
36-
{
37-
$this->gateway->completeAuthorize(array());
38-
}
39-
40-
/**
41-
* @expectedException \Omnipay\Common\Exception\BadMethodCallException
42-
*/
43-
public function testCapture()
44-
{
45-
$this->gateway->capture(array());
46-
}
47-
48-
/**
49-
* @expectedException \Omnipay\Common\Exception\BadMethodCallException
50-
*/
51-
public function testPurchase()
52-
{
53-
$this->gateway->purchase(array());
54-
}
55-
56-
/**
57-
* @expectedException \Omnipay\Common\Exception\BadMethodCallException
58-
*/
59-
public function testCompletePurchase()
60-
{
61-
$this->gateway->completePurchase(array());
62-
}
63-
64-
/**
65-
* @expectedException \Omnipay\Common\Exception\BadMethodCallException
66-
*/
67-
public function testRefund()
68-
{
69-
$this->gateway->refund(array());
70-
}
71-
72-
/**
73-
* @expectedException \Omnipay\Common\Exception\BadMethodCallException
74-
*/
75-
public function testVoid()
76-
{
77-
$this->gateway->void(array());
21+
$this->gateway = m::mock("\Omnipay\Common\AbstractGateway[getName,getDefaultParameters,purchase]");
7822
}
7923

8024
public function testGetShortName()

tests/Omnipay/Common/Message/AbstractRequestTest.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function setUp()
2525

2626
public function testInitializeWithParams()
2727
{
28-
$this->request->initialize(array('amount' => 123));
28+
$this->assertSame($this->request, $this->request->initialize(array('amount' => 123)));
2929
$this->assertSame(123, $this->request->getAmount());
3030
}
3131

@@ -40,7 +40,7 @@ public function testCard()
4040
public function testSetCardWithArray()
4141
{
4242
// passing array should create CreditCard object
43-
$this->request->setCard(array('number' => '1234'));
43+
$this->assertSame($this->request, $this->request->setCard(array('number' => '1234')));
4444

4545
$card = $this->request->getCard();
4646
$this->assertInstanceOf('\Omnipay\Common\CreditCard', $card);
@@ -49,92 +49,98 @@ public function testSetCardWithArray()
4949

5050
public function testCardToken()
5151
{
52-
$this->request->setCardToken('12345');
52+
$this->assertSame($this->request, $this->request->setCardToken('12345'));
5353
$this->assertSame('12345', $this->request->getCardToken());
5454
}
5555

56+
public function testCardReference()
57+
{
58+
$this->assertSame($this->request, $this->request->setCardReference('12345'));
59+
$this->assertSame('12345', $this->request->getCardReference());
60+
}
61+
5662
public function testAmount()
5763
{
58-
$this->request->setAmount(200);
64+
$this->assertSame($this->request, $this->request->setAmount(200));
5965
$this->assertSame(200, $this->request->getAmount());
6066
}
6167

6268
public function testAmountCastsToInteger()
6369
{
64-
$this->request->setAmount('6.1');
70+
$this->assertSame($this->request, $this->request->setAmount('6.1'));
6571
$this->assertSame(6, $this->request->getAmount());
6672
}
6773

6874
public function testGetAmountDecimal()
6975
{
70-
$this->request->setAmount(1366);
76+
$this->assertSame($this->request, $this->request->setAmount(1366));
7177
$this->assertSame('13.66', $this->request->getAmountDecimal());
7278
}
7379

7480
public function testGetAmountDecimalNoDecimals()
7581
{
76-
$this->request->setCurrency('JPY');
77-
$this->request->setAmount(1366);
82+
$this->assertSame($this->request, $this->request->setCurrency('JPY'));
83+
$this->assertSame($this->request, $this->request->setAmount(1366));
7884
$this->assertSame('1366', $this->request->getAmountDecimal());
7985
}
8086

8187
public function testCurrency()
8288
{
83-
$this->request->setCurrency('USD');
89+
$this->assertSame($this->request, $this->request->setCurrency('USD'));
8490
$this->assertSame('USD', $this->request->getCurrency());
8591
}
8692

8793
public function testCurrencyLowercase()
8894
{
89-
$this->request->setCurrency('usd');
95+
$this->assertSame($this->request, $this->request->setCurrency('usd'));
9096
$this->assertSame('USD', $this->request->getCurrency());
9197
}
9298

9399
public function testCurrencyNumeric()
94100
{
95-
$this->request->setCurrency('USD');
101+
$this->assertSame($this->request, $this->request->setCurrency('USD'));
96102
$this->assertSame('840', $this->request->getCurrencyNumeric());
97103
}
98104

99105
public function testCurrencyDecimals()
100106
{
101-
$this->request->setCurrency('JPY');
107+
$this->assertSame($this->request, $this->request->setCurrency('JPY'));
102108
$this->assertSame(0, $this->request->getCurrencyDecimalPlaces());
103109
}
104110

105111
public function testDescription()
106112
{
107-
$this->request->setDescription('Cool product');
113+
$this->assertSame($this->request, $this->request->setDescription('Cool product'));
108114
$this->assertSame('Cool product', $this->request->getDescription());
109115
}
110116

111117
public function testTransactionId()
112118
{
113-
$this->request->setTransactionId(87);
119+
$this->assertSame($this->request, $this->request->setTransactionId(87));
114120
$this->assertSame(87, $this->request->getTransactionId());
115121
}
116122

117123
public function testTransactionReference()
118124
{
119-
$this->request->setTransactionReference('xyz');
125+
$this->assertSame($this->request, $this->request->setTransactionReference('xyz'));
120126
$this->assertSame('xyz', $this->request->getTransactionReference());
121127
}
122128

123129
public function testClientIp()
124130
{
125-
$this->request->setClientIp('127.0.0.1');
131+
$this->assertSame($this->request, $this->request->setClientIp('127.0.0.1'));
126132
$this->assertSame('127.0.0.1', $this->request->getClientIp());
127133
}
128134

129135
public function testReturnUrl()
130136
{
131-
$this->request->setReturnUrl('https://www.example.com/return');
137+
$this->assertSame($this->request, $this->request->setReturnUrl('https://www.example.com/return'));
132138
$this->assertSame('https://www.example.com/return', $this->request->getReturnUrl());
133139
}
134140

135141
public function testCancelUrl()
136142
{
137-
$this->request->setCancelUrl('https://www.example.com/cancel');
143+
$this->assertSame($this->request, $this->request->setCancelUrl('https://www.example.com/cancel'));
138144
$this->assertSame('https://www.example.com/cancel', $this->request->getCancelUrl());
139145
}
140146
}

0 commit comments

Comments
 (0)