Skip to content

Commit d287068

Browse files
committed
Added: Token Delete method
1 parent bdd949c commit d287068

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

includes/modules/Payment/merchant_token_sample/class.merchant_token_sample.php

+29-17
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ class Merchant_Token_Sample extends TokenPaymentModule {
5656
)
5757
);
5858

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+
5978
/**
6079
* HostBill will call this method to attempt to charge/capture payment from credit card
6180
*
@@ -65,11 +84,15 @@ class Merchant_Token_Sample extends TokenPaymentModule {
6584
* $ccdetails['cardtype'] - CC type, ie. 'Visa'
6685
* If CVV is passed it will be available under:
6786
* $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+
*
6891
* @return boolean True if card was charged
6992
*/
70-
public function capture($ccdetails) {
71-
93+
public function capture_token($ccdetails) {
7294

95+
$options=array();
7396
$options['x_login'] = $this->configuration['API Login']['value'];
7497
$options['x_tran_key'] = $this->configuration['Transaction Key']['value'];
7598

@@ -93,12 +116,10 @@ public function capture($ccdetails) {
93116
$options['x_amount'] = $this->amount;
94117

95118

96-
97-
98119
/* CREDIT CARD INFORMATION */
99-
// we have token available, use it against registrar
120+
// we have token available, use it against payment gateway
100121
if ($ccdetails['token']) {
101-
$options['x_card_token'] = $ccdetails['cardnum'];
122+
$options['x_card_token'] = $ccdetails['token'];
102123
} else {
103124
$options['x_card_num'] = $ccdetails['cardnum'];
104125
$options['x_exp_date'] = $ccdetails['expdate']; //MMYY
@@ -109,9 +130,6 @@ public function capture($ccdetails) {
109130
}
110131

111132

112-
113-
114-
115133
//
116134
//SEND details to your credit card processor to validate and attempt to charge
117135
//
@@ -120,13 +138,10 @@ public function capture($ccdetails) {
120138
switch ($response['code']) {
121139
case 1:
122140
//charge succeeded, add transaction and log it
123-
124141
$this->logActivity(array(
125142
'output' => $response,
126143
'result' => PaymentModule::PAYMENT_SUCCESS
127144
));
128-
129-
130145
$this->addTransaction(array(
131146
'client_id' => $this->client['client_id'],
132147
'invoice_id' => $this->invoice_id,
@@ -136,25 +151,22 @@ public function capture($ccdetails) {
136151
'fee' => '0'
137152
));
138153

139-
if($response['Token']) {
154+
//Store token only if client allowed to - $ccetails['store']==true
155+
if($response['Token'] && $ccdetails['store']) {
140156
return $response['Token']; //return token to be stored
141157
} else {
142158
return true; //capture success
143159
}
144-
145160
break;
146161

147162
case 2:
148-
149163
$this->logActivity(array(
150164
'output' => $response,
151165
'result' => PaymentModule::PAYMENT_FAILURE
152166
));
153167
return false;
154168

155169
break;
156-
157-
158170
}
159171
}
160172

0 commit comments

Comments
 (0)