Skip to content

Commit dc79ff2

Browse files
author
Maksim Rafalko
committed
Merge remote-tracking branch 'upstream/master'
2 parents d380791 + 2985281 commit dc79ff2

30 files changed

+876
-237
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.3.3
54
- 5.3
65
- 5.4
76

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ to your `composer.json` file:
6464
```json
6565
{
6666
"require": {
67-
"omnipay/omnipay": "0.8.*"
67+
"omnipay/omnipay": "0.9.*"
6868
}
6969
}
7070
```
@@ -254,9 +254,6 @@ $request = $gateway->authorize([
254254
]);
255255
```
256256

257-
For most transactions, either the `card` or `token` parameter is required. For more information on
258-
using tokens, see the Token Billing section below.
259-
260257
When calling the `completeAuthorize` or `completePurchase` methods, the exact same arguments should be provided as
261258
when you made the initial `authorize` or `purchase` call (some gateways will need to verify for example the actual
262259
amount paid equals the amount requested). The only parameter you can omit is `card`.
@@ -348,13 +345,18 @@ try {
348345

349346
## Token Billing
350347

351-
Token billing is still under development. Most likely gateways will be able to implement the
352-
following methods:
348+
Token billing allows you to store a credit card with your gateway, and charge it at a later date.
349+
Token billing is not supported by all gateways. For supported gateways, the following methods
350+
are available:
353351

354-
* `createCard($options)` - returns a response object which includes a `token`, which can be used for future transactions
352+
* `createCard($options)` - returns a response object which includes a `cardReference`, which can be used for future transactions
355353
* `updateCard($options)` - update a stored card, not all gateways support this method
356354
* `deleteCard($options)` - remove a stored card, not all gateways support this method
357355

356+
Once you have a `cardReference`, you can use it instead of the `card` parameter when creating a charge:
357+
358+
$gateway->purchase(['amount' => 1000, 'cardReference' => 'abc']);
359+
358360
## Recurring Billing
359361

360362
At this stage, automatic recurring payments functionality is out of scope for this library.

src/Omnipay/Common/Message/AbstractRequest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ public function getCard()
134134

135135
public function setCard($value)
136136
{
137-
if (!$value instanceof CreditCard) {
137+
if ($value && !$value instanceof CreditCard) {
138138
$value = new CreditCard($value);
139139
}
140140

141141
return $this->setParameter('card', $value);
142142
}
143143

144-
public function getCardToken()
144+
public function getToken()
145145
{
146-
return $this->getParameter('cardToken');
146+
return $this->getParameter('token');
147147
}
148148

149-
public function setCardToken($value)
149+
public function setToken($value)
150150
{
151-
return $this->setParameter('cardToken', $value);
151+
return $this->setParameter('token', $value);
152152
}
153153

154154
public function getCardReference()

src/Omnipay/PayPal/ExpressGateway.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function getDefaultParameters()
3030
$settings = parent::getDefaultParameters();
3131
$settings['solutionType'] = array('Sole', 'Mark');
3232
$settings['landingPage'] = array('Billing', 'Login');
33+
$settings['headerImageUrl'] = '';
3334

3435
return $settings;
3536
}
@@ -54,6 +55,25 @@ public function setLandingPage($value)
5455
return $this->setParameter('landingPage', $value);
5556
}
5657

58+
public function getHeaderImageUrl()
59+
{
60+
return $this->getParameter('headerImageUrl');
61+
}
62+
63+
/**
64+
* Header Image URL (Optional)
65+
*
66+
* URL for the image you want to appear at the top left of the payment page.
67+
* The image has a maximum size of 750 pixels wide by 90 pixels high.
68+
* PayPal recommends that you provide an image that is stored on a secure (https) server.
69+
* If you do not specify an image, the business name displays.
70+
* Character length and limitations: 127 single-byte alphanumeric characters
71+
*/
72+
public function setHeaderImageUrl($value)
73+
{
74+
return $this->setParameter('headerImageUrl', $value);
75+
}
76+
5777
public function authorize(array $parameters = array())
5878
{
5979
return $this->createRequest('\Omnipay\PayPal\Message\ExpressAuthorizeRequest', $parameters);

src/Omnipay/PayPal/Message/AbstractRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public function setLandingPage($value)
6969
return $this->setParameter('landingPage', $value);
7070
}
7171

72+
public function getHeaderImageUrl()
73+
{
74+
return $this->getParameter('headerImageUrl');
75+
}
76+
77+
public function setHeaderImageUrl($value)
78+
{
79+
return $this->setParameter('headerImageUrl', $value);
80+
}
81+
7282
protected function getBaseData($method)
7383
{
7484
$data = array();

src/Omnipay/PayPal/Message/ExpressAuthorizeRequest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function getData()
3636
$data['RETURNURL'] = $this->getReturnUrl();
3737
$data['CANCELURL'] = $this->getCancelUrl();
3838

39+
if ($headerImageUrl = $this->getHeaderImageUrl()) {
40+
$data['HDRIMG'] = $headerImageUrl;
41+
}
42+
3943
if ($card = $this->getCard()) {
4044
$data['PAYMENTREQUEST_0_SHIPTONAME'] = $card->getName();
4145
$data['PAYMENTREQUEST_0_SHIPTOSTREET'] = $card->getAddress1();

src/Omnipay/Stripe/Gateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public function setApiKey($value)
4444
return $this->setParameter('apiKey', $value);
4545
}
4646

47+
public function authorize(array $parameters = array())
48+
{
49+
return $this->createRequest('\Omnipay\Stripe\Message\AuthorizeRequest', $parameters);
50+
}
51+
52+
public function capture(array $parameters = array())
53+
{
54+
return $this->createRequest('\Omnipay\Stripe\Message\CaptureRequest', $parameters);
55+
}
56+
4757
public function purchase(array $parameters = array())
4858
{
4959
return $this->createRequest('\Omnipay\Stripe\Message\PurchaseRequest', $parameters);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Stripe\Message;
13+
14+
/**
15+
* Stripe Abstract Request
16+
*/
17+
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
18+
{
19+
protected $endpoint = 'https://api.stripe.com/v1';
20+
21+
public function getApiKey()
22+
{
23+
return $this->getParameter('apiKey');
24+
}
25+
26+
public function setApiKey($value)
27+
{
28+
return $this->setParameter('apiKey', $value);
29+
}
30+
31+
/**
32+
* @deprecated
33+
*/
34+
public function getCardToken()
35+
{
36+
return $this->getParameter('token');
37+
}
38+
39+
/**
40+
* @deprecated
41+
*/
42+
public function setCardToken($value)
43+
{
44+
return $this->setParameter('token', $value);
45+
}
46+
47+
abstract public function getEndpoint();
48+
49+
public function getHttpMethod()
50+
{
51+
return 'POST';
52+
}
53+
54+
public function send()
55+
{
56+
// don't throw exceptions for 4xx errors
57+
$this->httpClient->getEventDispatcher()->addListener(
58+
'request.error',
59+
function ($event) {
60+
if ($event['response']->isClientError()) {
61+
$event->stopPropagation();
62+
}
63+
}
64+
);
65+
66+
$httpRequest = $this->httpClient->createRequest(
67+
$this->getHttpMethod(),
68+
$this->getEndpoint(),
69+
null,
70+
$this->getData()
71+
);
72+
$httpResponse = $httpRequest
73+
->setHeader('Authorization', 'Basic '.base64_encode($this->getApiKey().':'))
74+
->send();
75+
76+
return $this->response = new Response($this, $httpResponse->json());
77+
}
78+
79+
protected function getCardData()
80+
{
81+
$this->getCard()->validate();
82+
83+
$data = array();
84+
$data['number'] = $this->getCard()->getNumber();
85+
$data['exp_month'] = $this->getCard()->getExpiryMonth();
86+
$data['exp_year'] = $this->getCard()->getExpiryYear();
87+
$data['cvc'] = $this->getCard()->getCvv();
88+
$data['name'] = $this->getCard()->getName();
89+
$data['address_line1'] = $this->getCard()->getAddress1();
90+
$data['address_line2'] = $this->getCard()->getAddress2();
91+
$data['address_city'] = $this->getCard()->getCity();
92+
$data['address_zip'] = $this->getCard()->getPostcode();
93+
$data['address_state'] = $this->getCard()->getState();
94+
$data['address_country'] = $this->getCard()->getCountry();
95+
96+
return $data;
97+
}
98+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Stripe\Message;
13+
14+
/**
15+
* Stripe Authorize Request
16+
*/
17+
class AuthorizeRequest extends AbstractRequest
18+
{
19+
public function getData()
20+
{
21+
$this->validate('amount', 'currency');
22+
23+
$data = array();
24+
$data['amount'] = $this->getAmount();
25+
$data['currency'] = strtolower($this->getCurrency());
26+
$data['description'] = $this->getDescription();
27+
$data['capture'] = 'false';
28+
29+
if ($this->getCardReference()) {
30+
$data['customer'] = $this->getCardReference();
31+
} elseif ($this->getToken()) {
32+
$data['card'] = $this->getToken();
33+
} elseif ($this->getCard()) {
34+
$data['card'] = $this->getCardData();
35+
} else {
36+
// one of cardReference, token, or card is required
37+
$this->validate('card');
38+
}
39+
40+
return $data;
41+
}
42+
43+
public function getEndpoint()
44+
{
45+
return $this->endpoint.'/charges';
46+
}
47+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\Stripe\Message;
13+
14+
/**
15+
* Stripe Capture Request
16+
*/
17+
class CaptureRequest extends AbstractRequest
18+
{
19+
public function getData()
20+
{
21+
$this->validate('transactionReference');
22+
23+
$data = array();
24+
25+
if ($amount = $this->getAmount()) {
26+
$data['amount'] = $amount;
27+
}
28+
29+
return $data;
30+
}
31+
32+
public function getEndpoint()
33+
{
34+
return $this->endpoint.'/charges/'.$this->getTransactionReference().'/capture';
35+
}
36+
}

0 commit comments

Comments
 (0)