/[drupal]/contributions/modules/ec_eway/ec_eway.module
ViewVC logotype

Contents of /contributions/modules/ec_eway/ec_eway.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Wed Apr 15 23:38:48 2009 UTC (7 months, 1 week ago) by gordon
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA3, HEAD
Changes since 1.5: +23 -18 lines
File MIME type: text/x-php
* Add passing of the additional information to the eway gateway
1 <?php
2 // $Id: ec_eway.module,v 1.5 2008/12/08 12:26:27 gordon Exp $
3
4 /**
5 * @file
6 * eway payment gateway integration
7 */
8
9 /**
10 * Implementation of hook_menu().
11 */
12 function ec_eway_menu() {
13 $items = array();
14
15 $items['admin/ecsettings/rtypes/eway/settings'] = array(
16 'title' => 'Settings',
17 'page callback' => 'drupal_get_form',
18 'page arguments' => array('ec_eway_settings'),
19 'access arguments' => array('administer receipt settings'),
20 'type' => MENU_LOCAL_TASK,
21 );
22
23 return $items;
24 }
25
26 /**
27 * eWAY Settings Page
28 */
29 function ec_eway_settings() {
30 $form = array();
31
32 $form['ec_eway_clientid'] = array(
33 '#type' => 'textfield',
34 '#title' => t('eWAY Client Id'),
35 '#default_value' => variable_get('ec_eway_clientid', '87654321'),
36 '#size' => 70,
37 '#maxlength' => 70,
38 '#description' => t("Client Id that was issued by eWAY"),
39 '#required' => TRUE,
40 );
41 $form['ec_eway_default_description'] = array(
42 '#type' => 'textfield',
43 '#title' => t('Default Invoice Description'),
44 '#default_value' => variable_get('ec_eway_default_description', ''),
45 '#size' => 70,
46 '#maxlength' => 70,
47 '#description' => t("The default description that appears on an invoice"),
48 '#required' => TRUE,
49 );
50 $form['ec_eway_debug'] = array(
51 '#type' => 'radios',
52 '#title' => t('eWAY test mode'),
53 '#default_value' => variable_get('ec_eway_debug', 1),
54 '#options' => array(t('Disabled'), t('Enabled')),
55 '#description' => t('If enabled, transactions will be sent in test mode and cards will not be charged.'),
56 );
57
58 return system_settings_form($form);
59 }
60
61 /**
62 * Implementation of hook_receipt_info().
63 */
64 function ec_eway_receipt_info() {
65 return array(
66 'eway' => array(
67 'name' => t('eWAY'),
68 'description' => t('eWAY - Australia\'s Leading Payment Gateway'),
69 'module' => array('ec_eway'),
70 'allow_payments' => TRUE,
71 'allow_admin_payments' => TRUE,
72 'currencies_supported' => array('AUD'),
73 ),
74 );
75 }
76
77 /**
78 * Implementation of hook_receipt_payment_form().
79 */
80 function ec_eway_receipt_payment_form($type, $object) {
81 $form['cc'] = array(
82 '#type' => 'credit_card',
83 '#title' => t('Credit card details'),
84 '#cvnrequired' => TRUE,
85 );
86 return $form;
87 }
88
89 /**
90 * Implementation of hook_receipt_process_payment().
91 */
92 function ec_eway_receipt_process_payment($receipt, $atype, $object) {
93 // set the correct URL
94 if (variable_get('ec_eway_debug', 1)) {
95 $gateway_url = 'https://www.eway.com.au/gateway/xmltest/TestPage.asp';
96 }
97 else {
98 $gateway_url = 'https://www.eway.com.au/gateway/xmlpayment.asp';
99 }
100
101 $request = array(
102 'ewayCustomerID' => variable_get('ec_eway_clientid', '87654321'),
103 'ewayCustomerInvoiceDescription' => variable_get('ec_eway_default_description', ''),
104 'ewayCustomerEmail' => ec_receipt_alloc_invoke($atype, 'get_mail', $object),
105 'ewayCustomerInvoiceRef' => ec_receipt_alloc_invoke($atype, 'get_invoice_no', $object),
106 'ewayTrxnNumber' => $receipt->erid,
107 'ewayOption1' => '',
108 'ewayOption2' => '',
109 'ewayOption3' => '',
110 );
111 if ($total = ec_receipt_alloc_invoke($atype, 'get_total', $object)) {
112 //Accepts Total in Cents
113 $request['ewayTotalAmount'] = number_format($total, 2, '', '');
114 }
115 if ($cc = ec_receipt_alloc_invoke($atype, 'get_payment_data', $object)) {
116 $request['ewayCardHoldersName'] = $cc['cc']['name'];
117 $request['ewayCardNumber'] = $cc['cc']['cardnumber'];
118 $request['ewayCardExpiryMonth'] = $cc['cc']['expiry']['expmonth'];
119 $request['ewayCardExpiryYear'] = $cc['cc']['expiry']['expyear'];
120 if (!empty($cc['cc']['cvn'])) {
121 $request['ewayCVN'] = $cc['cc']['cvn'];
122 }
123 // set the correct URL
124 if (variable_get('ec_eway_debug', 1)) {
125 $gateway_url = 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp';
126 }
127 else {
128 $gateway_url = 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp';
129 }
130 }
131
132 if ($name = ec_receipt_alloc_invoke($atype, 'get_customer_names', $object)) {
133 $request['ewayCustomerFirstName'] = $name['fname'];
134 $request['ewayCustomerLastName'] = $name['lname'];
135 }
136 else {
137 form_set_error('', t('Customer details are required to process your credit card'));
138 return;
139 }
140 if ($address = ec_receipt_alloc_invoke($atype, 'get_address', $object, 'billing')) {
141 $request['ewayCustomerAddress'] = $address['street1'] .', '. $address['street2'] .
142 " \n". $address['city'] .', '. $address['state'];
143 $request['ewayCustomerPostcode'] = $address['zip'];
144 }
145 else {
146 form_set_error('', t('Customer address is required to process your credit card'));
147 return;
148 }
149
150 $headers = array(
151 'Content-Type' => 'application/x-www-form-urlencoded',
152 );
153
154 $request_xml = '<ewaygateway>';
155 foreach ($request as $key => $value) {
156 $request_xml .= "<$key>$value</$key>";
157 }
158 $request_xml .= '</ewaygateway>';
159
160 $ret = drupal_http_request(variable_get('ec_eway_url', $gateway_url), $headers, 'POST', $request_xml);
161
162 if (!isset($ret->error)) {
163 $response = simplexml_load_string($ret->data);
164
165 switch ($response->ewayTrxnStatus) {
166 case 'True':
167 $receipt->status = RECEIPT_STATUS_COMPLETED;
168 $receipt->approval_code = $response->ewayAuthCode;
169 break;
170
171 case 'False':
172 $receipt->status = RECEIPT_STATUS_FAILED;
173 $receipt->response_text = $response->ewayTrxnError;
174 form_set_error('', $receipt->response_text);
175 break;
176 }
177 ec_receipt_save($receipt);
178 }
179 else {
180 form_set_error('', $ret->error);
181 }
182
183 return $receipt->erid;
184 }

  ViewVC Help
Powered by ViewVC 1.1.2