Skip to content

Commit b51ab7b

Browse files
leithdaneastmond
authored andcommitted
Subscriptions and php8 support
* create subscriptions * fetch customer payment profile details * start support for creating and getting webhooks * fix typos * Travis updates * unit tests
1 parent eb9226b commit b51ab7b

22 files changed

+1520
-24
lines changed

.travis.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
language: php
22

33
php:
4-
- 7.0
5-
- 7.1
64
- 7.2
75
- 7.3
8-
9-
# This triggers builds to run on the new TravisCI infrastructure.
10-
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
11-
sudo: false
6+
- 7.4
7+
- 8.0
128

139
## Cache composer
1410
cache:
@@ -19,8 +15,17 @@ env:
1915
global:
2016
- setup=basic
2117

22-
matrix:
18+
jobs:
2319
include:
20+
- php: 7.2
21+
env: setup=lowest
22+
allow_failures:
23+
- php: 7.3
24+
- php: 7.4
25+
26+
before_install:
27+
# Enable Xdebug coverage mode
28+
- echo 'xdebug.mode="coverage"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
2429

2530
install:
2631
- if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ information.
421421
The webhooks can be configured in the Authorize.Net account settings page.
422422
They can also be fully managed through a REST API, so that a merchant
423423
site can register for all the webhooks that it needs.
424-
*Note that the webhook management RESTful API has not yet been implemented here.*
424+
*Note that the webhook management RESTful API is only partially implemented here.*
425425

426426
Your notification handler is set up like this at your webhook endpoint:
427427

@@ -431,7 +431,7 @@ $gateway = Omnipay::create('AuthorizeNetApi_Api');
431431
$gateway->setAuthName($authName);
432432
$gateway->setTransactionKey($authKey);
433433
$gateway->setSignatureKey($signatureKey); // HMAC-256
434-
$gateway->setTestMode(true); // for false
434+
$gateway->setTestMode(true); // or false
435435

436436
$notification = $gateway->acceptNotification();
437437
```
@@ -495,7 +495,7 @@ Validation of the `signature` can be disabled if needed:
495495

496496
For consistency with other Omipay Drivers, this driver *may* make an
497497
opinionated decision on how the `transactionId` is passed into the
498-
notification handler, but only after researchign how other people are
498+
notification handler, but only after researching how other people are
499499
handling it.
500500
There is a front-end way to do it through an iframe, but it seems
501501
vulnerable to user manipulation to me.

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@
2323
"Omnipay\\AuthorizeNetApi\\": "src/"
2424
}
2525
},
26+
"repositories": [
27+
{
28+
"type": "vcs",
29+
"url": "https://github.com/PatronBase/authorizenet-objects"
30+
}
31+
],
2632
"require": {
2733
"omnipay/common": "^3",
28-
"academe/authorizenet-objects": "~0.7",
34+
"academe/authorizenet-objects": "subscription-support-dev",
2935
"symfony/property-access": "^3.2 || ^4.0"
3036
},
3137
"require-dev": {
@@ -34,7 +40,7 @@
3440
},
3541
"extra": {
3642
"branch-alias": {
37-
"dev-master": "3.0.x-dev"
43+
"dev-master": "3.2.x-dev"
3844
}
3945
}
4046
}

src/ApiGateway.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
use Omnipay\AuthorizeNetApi\Message\RefundRequest;
1515
use Omnipay\AuthorizeNetApi\Message\FetchTransactionRequest;
1616
use Omnipay\AuthorizeNetApi\Message\AcceptNotification;
17+
use Omnipay\AuthorizeNetApi\Message\AuthenticateTestRequest;
18+
use Omnipay\AuthorizeNetApi\Message\CustomerProfiles\GetCustomerPaymentProfileRequest;
19+
use Omnipay\AuthorizeNetApi\Message\RecurringBilling\CreateSubscriptionRequest;
20+
use Omnipay\AuthorizeNetApi\Message\Webhooks\CreateWebhookRequest;
21+
use Omnipay\AuthorizeNetApi\Message\Webhooks\GetWebhookRequest;
1722

1823
class ApiGateway extends AbstractGateway
1924
{
@@ -90,4 +95,59 @@ public function acceptNotification(array $parameters = [])
9095
$parameters
9196
);
9297
}
98+
99+
/**
100+
* Create a subscription
101+
*/
102+
public function createSubscription(array $parameters = [])
103+
{
104+
return $this->createRequest(
105+
CreateSubscriptionRequest::class,
106+
$parameters
107+
);
108+
}
109+
110+
/**
111+
* Fetch a customer payment profile
112+
*/
113+
public function getCustomerPaymentProfile(array $parameters = [])
114+
{
115+
return $this->createRequest(
116+
GetCustomerPaymentProfileRequest::class,
117+
$parameters
118+
);
119+
}
120+
121+
/**
122+
* Test current authentication credentials
123+
*/
124+
public function authenticateTest(array $parameters = [])
125+
{
126+
return $this->createRequest(
127+
AuthenticateTestRequest::class,
128+
$parameters
129+
);
130+
}
131+
132+
/**
133+
* Create a webhook
134+
*/
135+
public function createWebhook(array $parameters = [])
136+
{
137+
return $this->createRequest(
138+
CreateWebhookRequest::class,
139+
$parameters
140+
);
141+
}
142+
143+
/**
144+
* Get a webhook
145+
*/
146+
public function getWebhook(array $parameters = [])
147+
{
148+
return $this->createRequest(
149+
GetWebhookRequest::class,
150+
$parameters
151+
);
152+
}
93153
}

src/Message/AbstractRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Academe\AuthorizeNet\TransactionRequestInterface;
1414
use Academe\AuthorizeNet\Request\CreateTransaction;
1515
use Academe\AuthorizeNet\Request\AbstractRequest as ApiAbstractRequest;
16+
use Academe\AuthorizeNet\SubscriptionRequestInterface;
1617
use Omnipay\AuthorizeNetApi\Traits\HasGatewayParams;
1718

1819
abstract class AbstractRequest extends OmnipayAbstractRequest
@@ -30,7 +31,7 @@ abstract class AbstractRequest extends OmnipayAbstractRequest
3031
*/
3132
public function getAuth()
3233
{
33-
return new MerchantAuthentication($this->getAuthName(), $this->getTransactionKey());
34+
return new MerchantAuthentication($this->getAuthName(), $this->getTransactionKey());
3435
}
3536

3637
/**

src/Message/AcceptNotification.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function getTransactionReference()
102102
{
103103
$this->assertSignature();
104104

105-
if ($this->getEventTarget() === $this->getParsedData()::EVENT_TARGET_PAYMENT) {
105+
if ($this->getEventTarget() === Notification::EVENT_TARGET_PAYMENT) {
106106
return $this->getPayload()->getTransId();
107107
}
108108
}
@@ -123,7 +123,7 @@ public function getTransactionStatus()
123123
if ($responseCode === TransactionResponse::RESPONSE_CODE_APPROVED) {
124124
return static::STATUS_COMPLETED;
125125
} elseif ($responseCode === TransactionResponse::RESPONSE_CODE_PENDING) {
126-
return static::STATUS_PENDIND;
126+
return static::STATUS_PENDING;
127127
} elseif ($responseCode !== null) {
128128
return static::STATUS_FAILED;
129129
}
@@ -209,7 +209,7 @@ public function getPayload()
209209
*/
210210
public function getResponseCode()
211211
{
212-
if ($this->getEventTarget() === $this->getParsedData()::EVENT_TARGET_PAYMENT) {
212+
if ($this->getEventTarget() === Notification::EVENT_TARGET_PAYMENT) {
213213
return $this->getPayload()->getResponseCode();
214214
}
215215
}
@@ -219,7 +219,7 @@ public function getResponseCode()
219219
*/
220220
public function getAuthCode()
221221
{
222-
if ($this->getEventTarget() === $this->getParsedData()::EVENT_TARGET_PAYMENT) {
222+
if ($this->getEventTarget() === Notification::EVENT_TARGET_PAYMENT) {
223223
return $this->getPayload()->getAuthCode();
224224
}
225225
}
@@ -229,7 +229,7 @@ public function getAuthCode()
229229
*/
230230
public function getAvsResponse()
231231
{
232-
if ($this->getEventTarget() === $this->getParsedData()::EVENT_TARGET_PAYMENT) {
232+
if ($this->getEventTarget() === Notification::EVENT_TARGET_PAYMENT) {
233233
return $this->getPayload()->getAvsResponse();
234234
}
235235
}
@@ -239,7 +239,7 @@ public function getAvsResponse()
239239
*/
240240
public function getAuthAmount()
241241
{
242-
if ($this->getEventTarget() === $this->getParsedData()::EVENT_TARGET_PAYMENT) {
242+
if ($this->getEventTarget() === Notification::EVENT_TARGET_PAYMENT) {
243243
return $this->getPayload()->getAuthAmount();
244244
}
245245
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNetApi\Message;
4+
5+
use Academe\AuthorizeNet\Request\AuthenticateTest;
6+
7+
class AuthenticateTestRequest extends AbstractRequest
8+
{
9+
/**
10+
* Return the complete message object.
11+
*/
12+
public function getData()
13+
{
14+
return [];
15+
}
16+
17+
/**
18+
* Accept a subscription and send it as a request.
19+
*
20+
* @param array $data
21+
* @return Response
22+
*/
23+
public function sendData($data)
24+
{
25+
$request = new AuthenticateTest($this->getAuth());
26+
$response_data = $this->sendMessage($request);
27+
28+
return new Response($this, $response_data);
29+
}
30+
}

src/Message/AuthorizeRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public function getOpaqueDataValue()
394394
*/
395395
public function setOpaqueData($descriptor, $value)
396396
{
397-
$this->setOpaqueDataDataDescriptor($descriptor);
397+
$this->setOpaqueDataDescriptor($descriptor);
398398
$this->setOpaqueDataValue($value);
399399

400400
return $this;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNetApi\Message\CustomerProfiles;
4+
5+
use Academe\AuthorizeNet\Request\GetCustomerPaymentProfile;
6+
use Omnipay\AuthorizeNetApi\Message\AbstractRequest;
7+
8+
/**
9+
* Request to fetch the details of a customer payment profile
10+
*
11+
* @see https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
12+
*/
13+
class GetCustomerPaymentProfileRequest extends AbstractRequest
14+
{
15+
/**
16+
* Return the complete message object.
17+
* @return GetCustomerPaymentProfile
18+
*/
19+
public function getData()
20+
{
21+
$this->validate('customerProfileId', 'customerPaymentProfileId');
22+
23+
$request = new GetCustomerPaymentProfile(
24+
$this->getAuth(),
25+
$this->getCustomerProfileId(),
26+
$this->getCustomerPaymentProfileId()
27+
);
28+
29+
if ($this->getTransactionId()) {
30+
$request = $request->withRefId($this->getTransactionId());
31+
}
32+
33+
if ($this->getUnmaskExpirationDate() !== null) {
34+
$request = $request->withUnmaskExpirationDate($this->getUnmaskExpirationDate());
35+
}
36+
37+
return $request;
38+
}
39+
40+
/**
41+
* Accept payment profile details and send it as a request.
42+
*
43+
* @param GetCustomerPaymentProfile $data
44+
* @return PaymentProfileResponse
45+
*/
46+
public function sendData($data)
47+
{
48+
$response_data = $this->sendMessage($data);
49+
50+
return new PaymentProfileResponse($this, $response_data);
51+
}
52+
53+
/**
54+
* @param string $value The gateway ID for the customer profile
55+
* @return self
56+
*/
57+
public function setCustomerProfileId($value)
58+
{
59+
return $this->setParameter('customerProfileId', $value);
60+
}
61+
62+
/**
63+
* @return string
64+
*/
65+
public function getCustomerProfileId()
66+
{
67+
return $this->getParameter('customerProfileId');
68+
}
69+
70+
/**
71+
* @param string $value The gateway ID for the customer payment profile
72+
* @return self
73+
*/
74+
public function setCustomerPaymentProfileId($value)
75+
{
76+
return $this->setParameter('customerPaymentProfileId', $value);
77+
}
78+
79+
/**
80+
* @return string
81+
*/
82+
public function getCustomerPaymentProfileId()
83+
{
84+
return $this->getParameter('customerPaymentProfileId');
85+
}
86+
87+
/**
88+
* @param bool $value Whether or not to return the expiration date unmasked
89+
* @return self
90+
*/
91+
public function setUnmaskExpirationDate($value)
92+
{
93+
return $this->setParameter('unmaskExpirationDate', $value);
94+
}
95+
96+
/**
97+
* @return bool
98+
*/
99+
public function getUnmaskExpirationDate()
100+
{
101+
return $this->getParameter('unmaskExpirationDate');
102+
}
103+
}

0 commit comments

Comments
 (0)