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+ // Store Card Options
51+ public function setStoreCard ($ value )
52+ {
53+ return $ this ->setParameter ('storeCard ' , $ value );
54+ }
55+
56+ public function getStoreCard ()
57+ {
58+ return $ this ->getParameter ('storeCard ' );
59+ }
60+
61+ public function setStoredCardIndicator ($ value )
62+ {
63+ $ options = [
64+ 'single ' , 'recurringfixed ' , 'recurringvariable ' , 'installment ' ,
65+ 'recurringnoexpiry ' , 'recurringinitial ' , 'installmentinitial ' , 'credentialonfileinitial ' ,
66+ 'unscheduledcredentialonfileinitial ' , 'credentialonfile ' , 'unscheduledcredentialonfile ' ,
67+ 'incremental ' , 'resubmission ' , 'reauthorisation ' , 'delayedcharges ' , 'noshow '
68+ ];
69+
70+ if (!in_array ($ value , $ options )) {
71+ throw new InvalidRequestException ("Invalid option ' {$ value }' set for StoredCardIndicator. " );
72+ }
73+
74+ return $ this ->setParameter ('storeCardIndicator ' , $ value );
75+ }
76+
77+ public function getStoredCardIndicator ()
78+ {
79+ return $ this ->getParameter ('storeCardIndicator ' );
80+ }
81+
82+ // Metadata
83+ public function setMetadata ($ data )
84+ {
85+ return $ this ->setParameter ('metaData ' , $ data );
86+ }
87+
88+ public function getMetadata ()
89+ {
90+ return $ this ->getParameter ('metaData ' );
91+ }
92+
93+ // Recurring Frequency
94+ public function setRecurringFrequency ($ value )
95+ {
96+ $ options = [
97+ 'daily ' , 'weekly ' , 'every2weeks ' , 'every4weeks ' ,
98+ 'monthly ' , 'monthly28th ' , 'monthlylastcalendarday ' ,
99+ 'monthlysecondlastcalendarday ' , 'monthlythirdlastcalendarday ' ,
100+ 'twomonthly ' , 'threemonthly ' , 'fourmonthly ' , 'sixmonthly ' , 'annually '
101+ ];
102+
103+ if (!in_array ($ value , $ options )) {
104+ throw new InvalidRequestException ("Invalid option ' {$ value }' set for RecurringFrequency. " );
105+ }
106+
107+ return $ this ->setParameter ('recurringFrequency ' , $ value );
108+ }
109+
110+ public function getRecurringFrequency ()
111+ {
112+ return $ this ->getParameter ('recurringFrequency ' );
113+ }
114+
115+ // Endpoint selection based on test mode
116+ protected function getEndpoint ($ path = '' )
117+ {
118+ $ base = $ this ->getTestMode () ? self ::ENDPOINT_TEST : self ::ENDPOINT_LIVE ;
119+ return $ base . '/ ' . $ path ;
120+ }
121+ }
0 commit comments