Skip to content

Commit e1b7856

Browse files
committed
Merge branch 'refs/heads/refunds'
# Conflicts: # src/Gateway.php # src/Message/CompletePurchaseRequest.php # src/Message/CompletePurchaseResponse.php # src/Message/PurchaseRequest.php
2 parents b58d22f + c86ba96 commit e1b7856

8 files changed

+485
-220
lines changed

src/Gateway.php

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
use Omnipay\WindcaveHpp\Message\AcceptNotification;
77
use Omnipay\WindcaveHpp\Message\CompletePurchaseRequest;
88
use Omnipay\WindcaveHpp\Message\PurchaseRequest;
9+
use Omnipay\WindcaveHpp\Message\RefundRequest;
910

1011
/**
1112
* Windcave HPP Payment Gateway
1213
*/
13-
class Gateway extends AbstractGateway {
14+
class Gateway extends AbstractGateway
15+
{
1416
/**
1517
* Get name
1618
*
1719
* @return string
1820
*/
19-
public function getName() {
21+
public function getName()
22+
{
2023
return 'Windcave Hpp';
2124
}
2225

@@ -25,23 +28,28 @@ public function getName() {
2528
*
2629
* @return array
2730
*/
28-
public function getDefaultParameters() {
31+
public function getDefaultParameters()
32+
{
2933
return [];
3034
}
3135

32-
public function setApiUsername($value) {
36+
public function setApiUsername($value)
37+
{
3338
return $this->setParameter('apiUsername', $value);
3439
}
3540

36-
public function getApiUsername() {
41+
public function getApiUsername()
42+
{
3743
return $this->getParameter('apiUsername');
3844
}
3945

40-
public function setApiKey($value) {
46+
public function setApiKey($value)
47+
{
4148
return $this->setParameter('apiKey', $value);
4249
}
4350

44-
public function getApiKey() {
51+
public function getApiKey()
52+
{
4553
return $this->getParameter('apiKey');
4654
}
4755

@@ -52,31 +60,72 @@ public function getApiKey() {
5260
*
5361
* @return Omnipay\WindcaveHpp\Message\PurchaseRequest
5462
*/
55-
public function purchase(array $parameters = []) {
63+
public function purchase(array $parameters = [])
64+
{
5665
return $this->createRequest(
5766
PurchaseRequest::class,
5867
$parameters
5968
);
6069
}
6170

71+
public function createCard(array $parameters = [])
72+
{
73+
return $this->createRequest(
74+
PurchaseRequest::class,
75+
$parameters + ['store_card' => true]
76+
);
77+
}
78+
6279
/**
6380
* Complete a purchase process
6481
*
6582
* @param array $parameters
6683
*
6784
* @return Omnipay\WindcaveHpp\Message\CompletePurchaseRequest
6885
*/
69-
public function completePurchase(array $parameters = []) {
86+
public function completePurchase(array $parameters = [])
87+
{
7088
return $this->createRequest(
7189
CompletePurchaseRequest::class,
7290
$parameters
7391
);
7492
}
7593

76-
public function acceptNotification(array $parameters = []) {
94+
/**
95+
* Complete a purchase process and save card
96+
*
97+
* @param array $parameters
98+
*
99+
* @return Omnipay\WindcaveHpp\Message\CompletePurchaseRequest
100+
*/
101+
public function completeCreateCard(array $parameters = [])
102+
{
103+
return $this->createRequest(
104+
CompletePurchaseRequest::class,
105+
$parameters
106+
);
107+
}
108+
109+
public function acceptNotification(array $parameters = [])
110+
{
77111
return $this->createRequest(
78112
AcceptNotification::class,
79113
$parameters
80114
)->send();
81115
}
116+
117+
/**
118+
* Refund
119+
*
120+
* @param array $parameters Parameters
121+
*
122+
* @return Omnipay\WindcaveHpp\Message\RefundRequest
123+
*/
124+
public function refund(array $parameters = [])
125+
{
126+
return $this->createRequest(
127+
RefundRequest::class,
128+
$parameters
129+
);
130+
}
82131
}

src/Message/AcceptNotification.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,39 @@ public function getResponseText() {
7272
public function getMessage() {
7373
return $this->getResponseText() ?? '';
7474
}
75+
76+
public function getCard()
77+
{
78+
return $this->getTransactionResult()['card'] ?? '';
79+
}
80+
81+
public function getCardNumber()
82+
{
83+
return $this->getCard()['cardNumber'] ?? '';
84+
}
85+
86+
public function cardHolderName()
87+
{
88+
return $this->getCard()['cardHolderName'] ?? '';
89+
}
90+
91+
public function getCardExpiry()
92+
{
93+
return ($this->getCard()['dateExpiryMonth'] ?? '') . '/' . ($this->getCard()['dateExpiryYear'] ?? '');
94+
}
95+
96+
public function getCardType()
97+
{
98+
return $this->getCard()['type'] ?? '';
99+
}
100+
101+
public function getCardReference()
102+
{
103+
return $this->getCard()['id'] ?? null;
104+
}
105+
106+
public function getTransactionResult()
107+
{
108+
return $this->getTransaction() ?? [];
109+
}
75110
}

src/Message/BaseRequest.php

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?php
2+
3+
namespace Omnipay\WindcaveHpp\Message;
4+
5+
use Omnipay\Common\Message\AbstractRequest;
6+
use Omnipay\Common\Exception\InvalidRequestException;
7+
8+
abstract class BaseRequest extends AbstractRequest
9+
{
10+
const ENDPOINT_TEST = 'https://uat.windcave.com/api/v1';
11+
const ENDPOINT_LIVE = 'https://sec.windcave.com/api/v1';
12+
13+
// API Credentials
14+
public function setApiUsername($value)
15+
{
16+
return $this->setParameter('apiUsername', $value);
17+
}
18+
19+
public function getApiUsername()
20+
{
21+
return $this->getParameter('apiUsername');
22+
}
23+
24+
public function setApiKey($value)
25+
{
26+
return $this->setParameter('apiKey', $value);
27+
}
28+
29+
public function getApiKey()
30+
{
31+
return $this->getParameter('apiKey');
32+
}
33+
34+
protected function getAuthorization()
35+
{
36+
return base64_encode($this->getApiUsername() . ':' . $this->getApiKey());
37+
}
38+
39+
// Merchant Reference
40+
public function setMerchantReference($value)
41+
{
42+
return $this->setParameter('merchantReference', $value);
43+
}
44+
45+
public function getMerchantReference()
46+
{
47+
return $this->getParameter('merchantReference');
48+
}
49+
50+
public function setType($value)
51+
{
52+
return $this->setParameter('type', $value);
53+
}
54+
55+
public function getType()
56+
{
57+
return $this->getParameter('type') ?? 'purchase';
58+
}
59+
60+
public function setLanguage($value)
61+
{
62+
return $this->setParameter('language', $value);
63+
}
64+
65+
public function getLanguage()
66+
{
67+
return $this->getParameter('language') ?? 'en';
68+
}
69+
70+
/**
71+
* @param $list
72+
* Possible methods: ['card', 'account2account', 'alipay', 'applepay', 'googlepay', 'paypal', 'interac', 'unionpay', 'oxipay', 'visacheckout', 'wechat']
73+
*
74+
* @return PurchaseRequest
75+
*/
76+
public function setPaymentMethods($list)
77+
{
78+
$options = [
79+
'card', 'account2account', 'alipay', 'applepay',
80+
'googlepay', 'paypal', 'interac', 'unionpay',
81+
'oxipay', 'visacheckout', 'wechat'
82+
];
83+
84+
foreach ( $list as $method ) {
85+
if ( !in_array($method, $options) ) {
86+
throw new InvalidRequestException("Unknown payment method: {$method}");
87+
}
88+
}
89+
90+
return $this->setParameter('paymentMethods', $list);
91+
}
92+
93+
public function getPaymentMethods()
94+
{
95+
return $this->getParameter('paymentMethods');
96+
}
97+
98+
public function setCardTypes($list)
99+
{
100+
return $this->setParameter('cardTypes', $list);
101+
}
102+
103+
public function getCardTypes()
104+
{
105+
return $this->getParameter('cardTypes');
106+
}
107+
108+
public function setExpiresAt($value)
109+
{
110+
return $this->setParameter('expiresAt', $value);
111+
}
112+
113+
public function getExpiresAt()
114+
{
115+
return $this->getParameter('expiresAt');
116+
}
117+
118+
public function setDeclineUrl($url)
119+
{
120+
return $this->setParameter('declineUrl', $url);
121+
}
122+
123+
public function getDeclineUrl()
124+
{
125+
return $this->getParameter('declineUrl');
126+
}
127+
128+
public function setStoreCard($value)
129+
{
130+
return $this->setParameter('storeCard', $value);
131+
}
132+
133+
public function getStoreCard()
134+
{
135+
return $this->getParameter('storeCard');
136+
}
137+
138+
public function setStoredCardIndicator($value)
139+
{
140+
$options = [
141+
'single', 'recurringfixed', 'recurringvariable', 'installment',
142+
'recurringnoexpiry', 'recurringinitial', 'installmentinitial', 'credentialonfileinitial',
143+
'unscheduledcredentialonfileinitial', 'credentialonfile', 'unscheduledcredentialonfile', 'incremental',
144+
'resubmission', 'reauthorisation', 'delayedcharges', 'noshow'
145+
];
146+
147+
if ( ! in_array($value, $options) ) {
148+
throw new InvalidRequestException("Invalid option '{$value}' set for StoredCardIndicator.");
149+
}
150+
151+
return $this->setParameter('storedCardIndicator', $value);
152+
}
153+
154+
public function getStoredCardIndicator()
155+
{
156+
return $this->getParameter('storedCardIndicator');
157+
}
158+
159+
public function setMetadata($data)
160+
{
161+
return $this->setParameter('metaData', $data);
162+
}
163+
164+
public function getMetadata()
165+
{
166+
return $this->getParameter('metaData');
167+
}
168+
169+
170+
public function setRecurringFrequency($value)
171+
{
172+
$options = [
173+
'daily', 'weekly', 'every2weeks', 'every4weeks',
174+
'monthly', 'monthly28th', 'monthlylastcalendarday',
175+
'monthlysecondlastcalendarday', 'monthlythirdlastcalendarday',
176+
'twomonthly', 'threemonthly', 'fourmonthly', 'sixmonthly', 'annually'
177+
];
178+
179+
if ( ! in_array($value, $options) ) {
180+
throw new InvalidRequestException("Invalid option '{$value}' set for RecurringFrequency.");
181+
}
182+
183+
return $this->setParameter('recurringFrequency', $value);
184+
}
185+
186+
public function getRecurringFrequency()
187+
{
188+
return $this->getParameter('recurringFrequency');
189+
}
190+
191+
public function setRecurringExpiry($value)
192+
{
193+
// For scenarios where no expiry/end date is established i.e.,
194+
// subscription payments, the merchant web application should use "9999-12-31" as the value.
195+
196+
return $this->setParameter('recurringExpiry', $value);
197+
}
198+
199+
public function getRecurringExpiry()
200+
{
201+
return $this->getParameter('recurringExpiry');
202+
}
203+
204+
// Endpoint selection based on test mode
205+
protected function getEndpoint($path = '')
206+
{
207+
$base = $this->getTestMode() ? self::ENDPOINT_TEST : self::ENDPOINT_LIVE;
208+
return $base . '/' . $path;
209+
}
210+
}

0 commit comments

Comments
 (0)