@@ -56,6 +56,25 @@ class Merchant_Token_Sample extends TokenPaymentModule {
56
56
)
57
57
);
58
58
59
+ /**
60
+ * Client choose to remove his credit card, or enter new card.
61
+ * Old token should be remotely deleted - if method below is available it will be called
62
+ * before entering new card details
63
+ *
64
+ * @param array $ccdetails Old credit card details
65
+ * $ccdetails['token'] - token to remove
66
+ */
67
+ public function token_delete ($ ccdetails ) {
68
+
69
+ $ options =array ();
70
+ $ options ['x_login ' ] = $ this ->configuration ['API Login ' ]['value ' ];
71
+ $ options ['x_tran_key ' ] = $ this ->configuration ['Transaction Key ' ]['value ' ];
72
+ $ options ['x_card_token ' ] = $ ccdetails ['token ' ];
73
+ $ options ['x_action ' ] = 'Remove Token ' ;
74
+
75
+ $ this ->processData ($ options );
76
+ }
77
+
59
78
/**
60
79
* HostBill will call this method to attempt to charge/capture payment from credit card
61
80
*
@@ -65,11 +84,15 @@ class Merchant_Token_Sample extends TokenPaymentModule {
65
84
* $ccdetails['cardtype'] - CC type, ie. 'Visa'
66
85
* If CVV is passed it will be available under:
67
86
* $ccdetails['cvv']
87
+ *
88
+ * If card already been tokenized cardnum will consist only last 4 digits, and new element
89
+ * $ccdetails['token'] - token to capture payment from
90
+ *
68
91
* @return boolean True if card was charged
69
92
*/
70
- public function capture ($ ccdetails ) {
71
-
93
+ public function capture_token ($ ccdetails ) {
72
94
95
+ $ options =array ();
73
96
$ options ['x_login ' ] = $ this ->configuration ['API Login ' ]['value ' ];
74
97
$ options ['x_tran_key ' ] = $ this ->configuration ['Transaction Key ' ]['value ' ];
75
98
@@ -93,12 +116,10 @@ public function capture($ccdetails) {
93
116
$ options ['x_amount ' ] = $ this ->amount ;
94
117
95
118
96
-
97
-
98
119
/* CREDIT CARD INFORMATION */
99
- // we have token available, use it against registrar
120
+ // we have token available, use it against payment gateway
100
121
if ($ ccdetails ['token ' ]) {
101
- $ options ['x_card_token ' ] = $ ccdetails ['cardnum ' ];
122
+ $ options ['x_card_token ' ] = $ ccdetails ['token ' ];
102
123
} else {
103
124
$ options ['x_card_num ' ] = $ ccdetails ['cardnum ' ];
104
125
$ options ['x_exp_date ' ] = $ ccdetails ['expdate ' ]; //MMYY
@@ -109,9 +130,6 @@ public function capture($ccdetails) {
109
130
}
110
131
111
132
112
-
113
-
114
-
115
133
//
116
134
//SEND details to your credit card processor to validate and attempt to charge
117
135
//
@@ -120,13 +138,10 @@ public function capture($ccdetails) {
120
138
switch ($ response ['code ' ]) {
121
139
case 1 :
122
140
//charge succeeded, add transaction and log it
123
-
124
141
$ this ->logActivity (array (
125
142
'output ' => $ response ,
126
143
'result ' => PaymentModule::PAYMENT_SUCCESS
127
144
));
128
-
129
-
130
145
$ this ->addTransaction (array (
131
146
'client_id ' => $ this ->client ['client_id ' ],
132
147
'invoice_id ' => $ this ->invoice_id ,
@@ -136,25 +151,22 @@ public function capture($ccdetails) {
136
151
'fee ' => '0 '
137
152
));
138
153
139
- if ($ response ['Token ' ]) {
154
+ //Store token only if client allowed to - $ccetails['store']==true
155
+ if ($ response ['Token ' ] && $ ccdetails ['store ' ]) {
140
156
return $ response ['Token ' ]; //return token to be stored
141
157
} else {
142
158
return true ; //capture success
143
159
}
144
-
145
160
break ;
146
161
147
162
case 2 :
148
-
149
163
$ this ->logActivity (array (
150
164
'output ' => $ response ,
151
165
'result ' => PaymentModule::PAYMENT_FAILURE
152
166
));
153
167
return false ;
154
168
155
169
break ;
156
-
157
-
158
170
}
159
171
}
160
172
0 commit comments