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