| 1 |
<?php
|
| 2 |
// $Id: uc_setcom.module,v 1.4 2009/10/08 10:56:23 maxheadroom Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Integrates setcom.com's redirected payment service.
|
| 7 |
*
|
| 8 |
* Developed by Quentin Campbell (Max Headroom).
|
| 9 |
* Drupal 6 version development sponsored by http://www.synecobusinessit.co.za.
|
| 10 |
*/
|
| 11 |
require_once('uc_setcom.ca.inc');
|
| 12 |
/*******************************************************************************
|
| 13 |
* Hook Functions (Drupal)
|
| 14 |
******************************************************************************/
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_menu().
|
| 18 |
*/
|
| 19 |
function uc_setcom_menu() {
|
| 20 |
$items['cart/setcom/complete'] = array(
|
| 21 |
'title' => 'Setcom transaction result',
|
| 22 |
'page callback' => 'uc_setcom_complete',
|
| 23 |
'access callback' => TRUE,
|
| 24 |
'type' => MENU_CALLBACK,
|
| 25 |
);
|
| 26 |
return $items;
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Implementation of hook_form_alter().
|
| 31 |
*/
|
| 32 |
function uc_setcom_form_alter(&$form, &$form_state, $form_id) {
|
| 33 |
if ($form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {
|
| 34 |
$order = uc_order_load($order_id);
|
| 35 |
|
| 36 |
if ($order->payment_method == 'setcom') {
|
| 37 |
unset($form['submit']);
|
| 38 |
$form['#prefix'] = '<table style="display: inline; padding-top: 1em;"><tr><td>';
|
| 39 |
$form['#suffix'] = '</td><td>'. drupal_get_form('uc_setcom_form', $order) .'</td></tr></table>';
|
| 40 |
}
|
| 41 |
}
|
| 42 |
}
|
| 43 |
|
| 44 |
/*******************************************************************************
|
| 45 |
* Hook Functions (Ubercart)
|
| 46 |
******************************************************************************/
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Implementation of hook_payment_method().
|
| 50 |
*/
|
| 51 |
function uc_setcom_payment_method() {
|
| 52 |
|
| 53 |
$path = base_path() . drupal_get_path('module', 'uc_setcom');
|
| 54 |
$title = variable_get('uc_setcom_method_title', t('Payment via Setcom secure server:'));
|
| 55 |
$title .= '<br /><img src="'. $path .'/setcom_small.gif" style="position: relative; left: 2.5em;"><br>';
|
| 56 |
|
| 57 |
$methods[] = array(
|
| 58 |
'id' => 'setcom',
|
| 59 |
'name' => t('Setcom'),
|
| 60 |
'title' => $title,
|
| 61 |
'desc' => t('Redirect to Setcom payment gateway.'),
|
| 62 |
'callback' => 'uc_payment_method_setcom',
|
| 63 |
'weight' => 3,
|
| 64 |
'checkout' => TRUE,
|
| 65 |
'no_gateway' => TRUE,
|
| 66 |
);
|
| 67 |
return $methods;
|
| 68 |
}
|
| 69 |
|
| 70 |
/*******************************************************************************
|
| 71 |
* Callback Functions, Forms, and Tables
|
| 72 |
******************************************************************************/
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Callback for setcom payment method settings.
|
| 76 |
*/
|
| 77 |
function uc_payment_method_setcom($op, &$arg1) {
|
| 78 |
switch ($op) {
|
| 79 |
case 'cart-details':
|
| 80 |
return uc_setcom_get_details();
|
| 81 |
|
| 82 |
case 'cart-process':
|
| 83 |
$_SESSION['pay_method'] = $_POST['pay_method'];
|
| 84 |
return;
|
| 85 |
|
| 86 |
case 'settings':
|
| 87 |
//Setcom Settings
|
| 88 |
$form['setcom_settings'] = array(
|
| 89 |
'#type' => 'fieldset',
|
| 90 |
'#title' => t('Setcom settings'),
|
| 91 |
);
|
| 92 |
|
| 93 |
$form['setcom_settings']['setcom_transaction_mode'] = array(
|
| 94 |
'#type' => 'select',
|
| 95 |
'#title' => t('Transaction mode'),
|
| 96 |
'#description' => t('Transaction mode used for processing orders. Be sure that you do your testing in Test mode.'),
|
| 97 |
'#options' => array(
|
| 98 |
'production' => t('Production'),
|
| 99 |
'test' => t('Test'),
|
| 100 |
),
|
| 101 |
'#default_value' => variable_get('setcom_transaction_mode', 'test'),
|
| 102 |
);
|
| 103 |
|
| 104 |
$form['setcom_settings']['setcom_username'] = array(
|
| 105 |
'#type' => 'textfield',
|
| 106 |
'#title' => t('Setcom Username'),
|
| 107 |
'#default_value' => variable_get('setcom_username', ''),
|
| 108 |
'#description' => t('Username you are registered with at Setcom.'),
|
| 109 |
);
|
| 110 |
|
| 111 |
$form['setcom_settings']['setcom_pwd'] = array(
|
| 112 |
'#type' => 'textfield',
|
| 113 |
'#title' => t('Setcom Password'),
|
| 114 |
'#default_value' => variable_get('setcom_pwd', ' '),
|
| 115 |
'#description' => t('Password you are registered with at Setcom.'),
|
| 116 |
);
|
| 117 |
|
| 118 |
$form['setcom_settings']['setcom_merchant_id'] = array(
|
| 119 |
'#type' => 'textfield',
|
| 120 |
'#title' => t('Merchant ID'),
|
| 121 |
'#default_value' => variable_get('setcom_merchant_id', ''),
|
| 122 |
'#description' => t('Merchant ID provided by Setcom when you\'ve create a seller account with them.'),
|
| 123 |
);
|
| 124 |
|
| 125 |
$form['setcom_settings']['setcom_test_username'] = array(
|
| 126 |
'#type' => 'textfield',
|
| 127 |
'#title' => t('Setcom Username for <strong> testing</strong>'),
|
| 128 |
'#default_value' => variable_get('setcom_test_username', 'testseller3@setcom.com'),
|
| 129 |
'#description' => t('Username at Setcom for <strong>testing</strong>. You can use testseller1@setcom.com up to testseller5@setcom.com with the same password: "testseller". Please log in at www.setcom.com with the test user name and password and under Profile >> Selling Preferences >> Website Payment Preferences, enter the Return URL supplied below into the Redirect URL field under Auto-Redirect. '),
|
| 130 |
);
|
| 131 |
|
| 132 |
$form['setcom_settings']['setcom_test_pwd'] = array(
|
| 133 |
'#type' => 'textfield',
|
| 134 |
'#title' => t('Setcom Password for <strong> testing</strong>'),
|
| 135 |
'#default_value' => variable_get('setcom_test_pwd', 'testseller'),
|
| 136 |
'#description' => t('Password at Setcom for <strong>testing.</strong> Defaults to "testseller".'),
|
| 137 |
);
|
| 138 |
|
| 139 |
$form['setcom_settings']['setcom_test_merchant_id'] = array(
|
| 140 |
'#type' => 'textfield',
|
| 141 |
'#title' => t('Merchant ID for <strong> testing</strong>'),
|
| 142 |
'#default_value' => variable_get('setcom_test_merchant_id', '1234567893'),
|
| 143 |
'#description' => t('Merchant ID at Setcom for <strong>testing.</strong> Can range from 1234567891 to 1234567895, corresponding to the test email account you use '),
|
| 144 |
);
|
| 145 |
|
| 146 |
$form['setcom_settings']['setcom_return_url'] = array(
|
| 147 |
'#type' => 'item',
|
| 148 |
'#title' => t('Return URL'),
|
| 149 |
'#value' => variable_get('setcom_return_url', url('cart/setcom/complete/', $options = array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE))),
|
| 150 |
'#description' => t('The URL to where Setcom must return to after a transaction. Please log in to your Setcom account and under Profile >> Selling Preferences >> Website Payment Preferences, enter this Return URL into the Redirect URL field under Auto-Redirect.'),
|
| 151 |
);
|
| 152 |
|
| 153 |
$form['setcom_settings']['setcom_currency'] = array(
|
| 154 |
'#type' => 'select',
|
| 155 |
'#title' => t('Currency code'),
|
| 156 |
'#description' => t('Currency you use with your cart. Please note Setcom only use USD, EUR, GBP and ZAR.'),
|
| 157 |
'#options' => array(
|
| 158 |
'USD' => t('USD'),
|
| 159 |
'EUR' => t('EUR'),
|
| 160 |
'GBP' => t('GBP'),
|
| 161 |
'ZAR' => t('ZAR'),
|
| 162 |
),
|
| 163 |
'#default_value' => variable_get('setcom_currency', (variable_get('uc_currency_code', 'USD'))),
|
| 164 |
);
|
| 165 |
|
| 166 |
$form['setcom_settings']['setcom_template'] = array(
|
| 167 |
'#type' => 'textfield',
|
| 168 |
'#title' => t('Setcom template name'),
|
| 169 |
'#default_value' => variable_get('setcom_template', 0),
|
| 170 |
'#description' => t('Sets the Custom Payment Page Template for payment pages associated with this button/link. The value of TemplateID is the same as the Template Name you chose when adding or editing the page style. You can add and edit Custom Payment Page from the <strong>Selling Preferences</strong> subtab of the <strong>Profile</strong> tab. Maximum length of 30 characters. Valid character set is alphanumeric only, plus underscore. It cannot include spaces.'),
|
| 171 |
);
|
| 172 |
|
| 173 |
$form['setcom_settings']['setcom_buyer_info'] = array(
|
| 174 |
'#type' => 'checkbox',
|
| 175 |
'#title' => t('Send buyer information'),
|
| 176 |
'#default_value' => variable_get('setcom_buyer_info', TRUE),
|
| 177 |
'#description' => t('Send client information to Setcom so that their system pre-populate the signup form for new users.')
|
| 178 |
);
|
| 179 |
|
| 180 |
$form['setcom_settings']['setcom_shipping'] = array(
|
| 181 |
'#type' => 'checkbox',
|
| 182 |
'#title' => 'Setcom do shipping',
|
| 183 |
'#default_value' => variable_get('setcom_shipping', FALSE),
|
| 184 |
'#description' => t('Set if you want Setcom to handle shipping charges.'),
|
| 185 |
);
|
| 186 |
|
| 187 |
$form['setcom_settings']['setcom_do_email'] = array(
|
| 188 |
'#type' => 'checkbox',
|
| 189 |
'#title' => 'Send email on error',
|
| 190 |
'#default_value' => variable_get('setcom_do_email', TRUE),
|
| 191 |
'#description' => t('Send an email to address below if there was a transaction or communications error. Recommended'),
|
| 192 |
);
|
| 193 |
|
| 194 |
$form['setcom_settings']['setcom_error_email'] = array(
|
| 195 |
'#type' => 'textfield',
|
| 196 |
'#title' => t('Email for errors'),
|
| 197 |
'#default_value' => variable_get('setcom_error_email', variable_get('site_mail', ini_get('sendmail_from'))),
|
| 198 |
'#description' => t('Email address for error notifications. Defaults to site owner.'),
|
| 199 |
);
|
| 200 |
|
| 201 |
// $form['setcom_settings']['setcom_button_action'] = array(
|
| 202 |
// '#type' => 'textfield',
|
| 203 |
// '#title' => t('Setcom button action'),
|
| 204 |
// '#default_value' => variable_get('setcom_button_action', 'checkout'),
|
| 205 |
// '#description' => t(' This setting is here for future compatibility. Tells Setcom this is a Checkout Button. Should be set to <strong>\'checkout\'</strong>. This variable is required and should not be changed. Changing this argument will cause your Checkout to malfunction. '),
|
| 206 |
// );
|
| 207 |
|
| 208 |
//Setcom payment methods
|
| 209 |
$form['setcom_payment_methods'] = array(
|
| 210 |
'#type' => 'fieldset',
|
| 211 |
'#title' => t('Setcom payment methods'),
|
| 212 |
'#description' => t('Setcom allows for various payment methods fot buyers, but not all methods would be suitable for sellers. Some methods requires a waiting period of up to a few days for payment to clear. Setcom have all payments methods available on their site by default. You can request for payment methods to be removed by contacting Setcom. However, you must inform your buyers which payment methods you would accept'),
|
| 213 |
);
|
| 214 |
|
| 215 |
$allowed_options = array('Allow, and ship on order completed and payment received (payment is cleared immediately
|
| 216 |
)', 'Allow, and ship only after payment has cleared at a later date', 'Do not allow this option');
|
| 217 |
|
| 218 |
$form['setcom_payment_methods']['uc_setcom_credit_card'] = array(
|
| 219 |
'#type' => 'select',
|
| 220 |
'#title' => t('Allow payment by Credit Card'),
|
| 221 |
'#default_value' => variable_get('uc_setcom_credit_card', 0),
|
| 222 |
'#options' => $allowed_options,
|
| 223 |
);
|
| 224 |
|
| 225 |
$form['setcom_payment_methods']['uc_setcom_poli'] = array(
|
| 226 |
'#type' => 'select',
|
| 227 |
'#title' => t('Allow payment by Setcom POLi/SID'),
|
| 228 |
'#default_value' => variable_get('uc_setcom_poli', 0),
|
| 229 |
'#options' => $allowed_options,
|
| 230 |
);
|
| 231 |
|
| 232 |
$form['setcom_payment_methods']['uc_setcom_balance'] = array(
|
| 233 |
'#type' => 'select',
|
| 234 |
'#title' => t('Allow payment with available credit at Setcom'),
|
| 235 |
'#default_value' => variable_get('uc_setcom_balance', 0),
|
| 236 |
'#options' => $allowed_options,
|
| 237 |
);
|
| 238 |
|
| 239 |
$form['setcom_payment_methods']['uc_setcom_echeque'] = array(
|
| 240 |
'#type' => 'select',
|
| 241 |
'#title' => t('Allow payment by Setcom eCheque'),
|
| 242 |
'#default_value' => variable_get('uc_setcom_echeque', 2),
|
| 243 |
'#options' => $allowed_options,
|
| 244 |
);
|
| 245 |
|
| 246 |
$form['setcom_payment_methods']['uc_setcom_edeposit'] = array(
|
| 247 |
'#type' => 'select',
|
| 248 |
'#title' => t('Allow payment by Setcom eDeposit'),
|
| 249 |
'#default_value' => variable_get('uc_setcom_edeposit', 2),
|
| 250 |
'#options' => $allowed_options,
|
| 251 |
);
|
| 252 |
|
| 253 |
//Setcom Checkout
|
| 254 |
$form['setcom_checkout'] = array(
|
| 255 |
'#type' => 'fieldset',
|
| 256 |
'#title' => t('Setcom checkout settings'),
|
| 257 |
);
|
| 258 |
|
| 259 |
$form['setcom_checkout']['uc_setcom_method_title'] = array(
|
| 260 |
'#type' => 'textfield',
|
| 261 |
'#title' => t('Payment method title'),
|
| 262 |
'#default_value' => variable_get('uc_setcom_method_title', t('Payment via Setcom secure server.')),
|
| 263 |
);
|
| 264 |
|
| 265 |
$form['setcom_checkout']['uc_setcom_method_title_icons'] = array(
|
| 266 |
'#type' => 'checkbox',
|
| 267 |
'#title' => t('Show icons beside the payment method title.'),
|
| 268 |
'#default_value' => variable_get('uc_setcom_method_title_icons', TRUE),
|
| 269 |
);
|
| 270 |
|
| 271 |
$form['setcom_checkout']['uc_setcom_checkout_button'] = array(
|
| 272 |
'#type' => 'textfield',
|
| 273 |
'#title' => t('Order review submit button text'),
|
| 274 |
'#description' => t('Provide Setcom specific text for the submit button on the order review page.'),
|
| 275 |
'#default_value' => variable_get('uc_setcom_checkout_button', t('Submit Order')),
|
| 276 |
);
|
| 277 |
|
| 278 |
$form['setcom_checkout']['uc_checkout_review_instructions_format'] = filter_form(variable_get('uc_checkout_review_instructions_format', 3), NULL, array('uc_checkout_review_instructions_format'));
|
| 279 |
return $form;
|
| 280 |
}
|
| 281 |
}
|
| 282 |
|
| 283 |
// Form to build the submission to setcom.com
|
| 284 |
function uc_setcom_form(&$form_state, $order) {
|
| 285 |
global $user;
|
| 286 |
$country = uc_get_country_data(array('country_id' => $order->billing_country));
|
| 287 |
|
| 288 |
if (variable_get('setcom_transaction_mode', 'test') == 'production') {
|
| 289 |
$merchant_identifier = variable_get('setcom_merchant_id', '');
|
| 290 |
}
|
| 291 |
else{
|
| 292 |
$merchant_identifier = variable_get('setcom_test_merchant_id', '');
|
| 293 |
}
|
| 294 |
|
| 295 |
$data = array(
|
| 296 |
'ButtonAction' => variable_get('setcom_button_action', 'checkout'),
|
| 297 |
'merchantIdentifier' => $merchant_identifier,
|
| 298 |
'CurrencyAlphaCode' => variable_get('setcom_currency', (variable_get('uc_currency_code', 'USD'))),
|
| 299 |
'MerchCustom' => $order->order_id,
|
| 300 |
'TemplateID' => variable_get('setcom_template', 0),
|
| 301 |
'BuyerInformation' => variable_get('setcom_buyer_info', TRUE),
|
| 302 |
'FirstName' => $order->billing_first_name,
|
| 303 |
'LastName' => $order->billing_last_name,
|
| 304 |
'Address1' => $order->billing_street1,
|
| 305 |
'Address2' => $order->billing_street2,
|
| 306 |
'City' => $order->billing_city,
|
| 307 |
'State' => uc_get_zone_code($order->billing_zone),
|
| 308 |
'PostalCode' => $order->delivery_postal_code,
|
| 309 |
'Country' => $country['country_iso_code_2'],
|
| 310 |
'Email' => $order->primary_email,
|
| 311 |
'MobileNumber' => $order->billing_phone,
|
| 312 |
);
|
| 313 |
|
| 314 |
$i = 0;
|
| 315 |
foreach ($order->products as $product) {
|
| 316 |
$j =($i == 0)?'':$i;
|
| 317 |
$data['LIDSKU'. $j] = $product->model;
|
| 318 |
$data['LIDDesc'. $j] = $product->title;
|
| 319 |
$data['LIDPrice'. $j] = uc_currency_format($product->price, FALSE, FALSE, '.');
|
| 320 |
$data['LIDQty'. $j] = $product->qty;
|
| 321 |
$data['ShippingRequired'. $j] = variable_get('setcom_shipping', FALSE);
|
| 322 |
$data['IsVoucher'. $j] = 0;
|
| 323 |
$i++;
|
| 324 |
}
|
| 325 |
$do_shipping = variable_get('setcom_shipping', FALSE);
|
| 326 |
if (!$do_shipping) {
|
| 327 |
$data['LIDSKU'. $i] = 'shipping';
|
| 328 |
$data['LIDDesc'. $i] = 'Shipping cost';
|
| 329 |
$data['LIDPrice'. $i] = uc_currency_format($order->quote['rate'], FALSE, FALSE, '.');
|
| 330 |
$data['LIDQty'. $i] = 1;
|
| 331 |
$data['ShippingRequired'. $i] = 0;
|
| 332 |
$data['IsVoucher'. $i] = 0;
|
| 333 |
$i++;
|
| 334 |
}
|
| 335 |
|
| 336 |
$form['#action'] = 'https://www.setcom.com/secure/';
|
| 337 |
|
| 338 |
foreach ($data as $name => $value) {
|
| 339 |
$form[$name] = array('#type' => 'hidden', '#value' => $value);
|
| 340 |
}
|
| 341 |
|
| 342 |
$form['submit'] = array(
|
| 343 |
'#type' => 'submit',
|
| 344 |
'#value' => variable_get('uc_setcom_checkout_button', t('Submit Order')),
|
| 345 |
);
|
| 346 |
|
| 347 |
return $form;
|
| 348 |
}
|
| 349 |
|
| 350 |
function uc_setcom_complete($cart_id = 0) {
|
| 351 |
|
| 352 |
$s_front = url();
|
| 353 |
$tnxid=$_GET['tnxid'];
|
| 354 |
$checksum=$_GET['checksum'];
|
| 355 |
$parity=$_GET['parity'];
|
| 356 |
|
| 357 |
$page = variable_get('uc_cart_checkout_complete_page', '');
|
| 358 |
if (!empty($page)) {
|
| 359 |
drupal_goto(variable_get('uc_cart_checkout_complete_page', ''));
|
| 360 |
}
|
| 361 |
|
| 362 |
$err_msg = '';
|
| 363 |
if (empty($tnxid)) {
|
| 364 |
$err_msg .= 'tnxid not found.';
|
| 365 |
}
|
| 366 |
if (empty($checksum)) {
|
| 367 |
$err_msg .= 'checksum not found.';
|
| 368 |
}
|
| 369 |
if (empty($parity)) {
|
| 370 |
$err_msg .= 'parity not found.';
|
| 371 |
}
|
| 372 |
|
| 373 |
if ($err_msg) {
|
| 374 |
drupal_set_message('Communication error: '. $err_msg .'<br> No futher action or processing will be done.', 'error');
|
| 375 |
if (variable_get('setcom_do_email', TRUE) == TRUE) {
|
| 376 |
drupal_set_message('<b>The store owner has been notified and will look into the problem.', 'error');
|
| 377 |
uc_setcom_send_error('Communication error: '. $err_msg, 'Communication error: '. $err_msg .' No futher action or processing will be done.');
|
| 378 |
}
|
| 379 |
watchdog('Setcom', $err_msg, WATCHDOG_WARNING);
|
| 380 |
}
|
| 381 |
|
| 382 |
// Web page receives Synchro Auto-Redirect variables from Setcom.
|
| 383 |
if (variable_get('setcom_transaction_mode', 'test') == 'production') {
|
| 384 |
$merchant_identifier = variable_get('setcom_merchant_id', '');
|
| 385 |
$username = variable_get('setcom_username', '');
|
| 386 |
$password = variable_get('setcom_pwd', '');
|
| 387 |
}
|
| 388 |
else{
|
| 389 |
$merchant_identifier = variable_get('setcom_test_merchant_id', '1234567893');
|
| 390 |
$username = variable_get('setcom_test_username', 'testseller3@setcom.com');
|
| 391 |
$password = variable_get('setcom_test_pwd', 'testseller');
|
| 392 |
}
|
| 393 |
|
| 394 |
/*
|
| 395 |
Now we open a communication line to the HTTP Synchro Service.
|
| 396 |
*/
|
| 397 |
$setcom_string = 'method='.'order_synchro'.
|
| 398 |
'&identifier='. $merchant_identifier .
|
| 399 |
'&usrname='. $username .
|
| 400 |
'&pwd='. $password .
|
| 401 |
'&tnxid='. $tnxid .
|
| 402 |
'&checksum='. $checksum .
|
| 403 |
'&parity='. $parity;
|
| 404 |
|
| 405 |
// send $setcom_string to Setcom by utilizing CURL
|
| 406 |
$setcom_url = "https://www.setcom.com/secure/components/synchro.cfc?wsdl";
|
| 407 |
|
| 408 |
// Setcom Synchro url
|
| 409 |
$ch = curl_init(); // initialize curl handle
|
| 410 |
curl_setopt($ch, CURLOPT_URL, $setcom_url); // set $setcom_url to post to Setcom
|
| 411 |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
| 412 |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
| 413 |
curl_setopt($ch, CURLOPT_HEADER, 0);
|
| 414 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
|
| 415 |
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
|
| 416 |
curl_setopt($ch, CURLOPT_POSTFIELDS, $setcom_string); // set Post variable
|
| 417 |
$setcom_result = curl_exec($ch); // Perform the POST and get the data returned by Setcom.
|
| 418 |
if (curl_errno($ch)) {
|
| 419 |
$scurlerror = curl_error($ch); // If CURL returns an error, stores it in a variable.
|
| 420 |
Drupal_set_message($scurlerror);
|
| 421 |
}
|
| 422 |
else {
|
| 423 |
$scurlerror = '';
|
| 424 |
curl_close($ch);
|
| 425 |
}
|
| 426 |
if (empty($scurlerror)) {
|
| 427 |
//filter result for XML
|
| 428 |
$setcom_wddx = trim($setcom_result);
|
| 429 |
$setcom_xml = wddx_deserialize($setcom_wddx);
|
| 430 |
$order_synchro = simplexml_load_string($setcom_xml);
|
| 431 |
|
| 432 |
//tnx details
|
| 433 |
$tnx_status = $order_synchro->outcome->status;
|
| 434 |
$tnx_id = $order_synchro->outcome->order->id;
|
| 435 |
$funds_avail = $order_synchro->outcome->order->funds_available;
|
| 436 |
|
| 437 |
//error details
|
| 438 |
$error_code = $order_synchro->outcome->error_code;
|
| 439 |
$error_desc = $order_synchro->outcome->error_desc;
|
| 440 |
$error_solution = $order_synchro->outcome->error_solution;
|
| 441 |
|
| 442 |
//seller details
|
| 443 |
$seller_ref = $order_synchro->seller->reference;
|
| 444 |
$seller_email = $order_synchro->seller->username;
|
| 445 |
$order = uc_order_load($seller_ref);
|
| 446 |
|
| 447 |
//buyer details
|
| 448 |
$buyer_ref = $order_synchro->buyer->reference;
|
| 449 |
$buyer_uname = $order_synchro->buyer->username;
|
| 450 |
$buyer_title = $order_synchro->buyer->billing_address->title;
|
| 451 |
$buyer_fname = $order_synchro->buyer->billing_address->firstname;
|
| 452 |
$buyer_lname = $order_synchro->buyer->billing_address->lastname;
|
| 453 |
$buyer_email = $order_synchro->buyer->billing_address->email_address;
|
| 454 |
$buyer_street1 = $order_synchro->buyer->billing_address->street1;
|
| 455 |
$buyer_street2 = $order_synchro->buyer->billing_address->street2;
|
| 456 |
$buyer_city = $order_synchro->buyer->billing_address->city;
|
| 457 |
$buyer_state = $order_synchro->buyer->billing_address->state;
|
| 458 |
$buyer_zip = $order_synchro->buyer->billing_address->zip;
|
| 459 |
$buyer_country = $order_synchro->buyer->billing_address->country;
|
| 460 |
$buyer_cnumber = $order_synchro->buyer->billing_address->contact_number;
|
| 461 |
|
| 462 |
//payment details
|
| 463 |
$pmt_type = $order_synchro->payment_instrument->type;
|
| 464 |
|
| 465 |
//financial details
|
| 466 |
$tnx_amount = $order_synchro->financial->amount_total;
|
| 467 |
$currency = $order_synchro->financial->currency;
|
| 468 |
/*validation of transaction outcome in order to display the correct information to the buyer */
|
| 469 |
|
| 470 |
//transaction is unsuccessful
|
| 471 |
if ($error_code != '0') {
|
| 472 |
$somestring = '<strong>Your order has been Declined.</strong><br><br>';
|
| 473 |
$somestring .= 'Sorry '. $buyer_title .' '. $buyer_fname .' '. $buyer_surname .' your payment to '. $seller_email .' was <strong>unsuccesful</strong>.<br><br>';
|
| 474 |
$somestring .= ' The order has not been processed<br><br>';
|
| 475 |
$somestring .= 'Error Code: '. $error_code .'<br>';
|
| 476 |
$somestring .= 'Error Description: '. $error_desc .'<br>';
|
| 477 |
$somestring .= 'Error Solution: '. $error_solution .'<br>';
|
| 478 |
drupal_set_message($somestring, 'error');
|
| 479 |
watchdog('Setcom', $somestring, array(), WATCHDOG_WARNING);
|
| 480 |
$output = '<br /><a href="'. $s_front .'">Click to return to the front page.</a>';
|
| 481 |
}
|
| 482 |
else { //end transaction is unsuccessful
|
| 483 |
//transaction is successful
|
| 484 |
$cur_tnx_amount = getcurrency($tnx_amount, $currency);
|
| 485 |
$somearray['tnx_amount'] = $tnx_amount/100; //returned amount is without decimal
|
| 486 |
|
| 487 |
if (!$pmt_type) {
|
| 488 |
$somearray['pmt_type'] ='unknown type';
|
| 489 |
}
|
| 490 |
else{
|
| 491 |
$somearray['pmt_type'] = $pmt_type;
|
| 492 |
}
|
| 493 |
|
| 494 |
$somearray['order'] = $seller_ref;
|
| 495 |
$somestring = 'Your transaction is <strong>'. $tnx_status .'</strong><br><br>';
|
| 496 |
$somestring .= 'Payment by '. $somearray['pmt_type'] .'. <br>';
|
| 497 |
$somestring .= ' Thank you, '. $buyer_title .' '. $buyer_fname .' '. $buyer_surname .'for your business<br>';
|
| 498 |
$somestring .= '<strong>Transaction ID</strong>: '. $tnx_id .'<br>';
|
| 499 |
$somestring .= '<strong>Transaction Amount</strong>: '. $cur_tnx_amount .'<br>';
|
| 500 |
$somestring .= '<strong>Funds Available</strong>: '. $funds_avail .'<br>';
|
| 501 |
$somestring .= '<strong>Reference</strong>: '. $seller_ref .'<br>';
|
| 502 |
|
| 503 |
switch ($pmt_type) {
|
| 504 |
case 'Credit Card':
|
| 505 |
$somearray['setting'] = variable_get('uc_setcom_credit_card', 0);
|
| 506 |
list($output, $somestring) = uc_setcom_check_trans($somearray, $somestring);
|
| 507 |
break;
|
| 508 |
|
| 509 |
case 'POLi':
|
| 510 |
$somearray['setting'] = variable_get('uc_setcom_poli', 0);
|
| 511 |
list($output, $somestring) = uc_setcom_check_trans($somearray, $somestring);
|
| 512 |
break;
|
| 513 |
|
| 514 |
case 'Balance':
|
| 515 |
$somearray['setting'] = variable_get('uc_setcom_balance', 0);
|
| 516 |
list($output, $somestring) = uc_setcom_check_trans($somearray, $somestring);
|
| 517 |
break;
|
| 518 |
|
| 519 |
case 'eCheque':
|
| 520 |
$somearray['setting'] = variable_get('uc_setcom_echeque', 0);
|
| 521 |
list($output, $somestring) = uc_setcom_check_trans($somearray, $somestring);
|
| 522 |
break;
|
| 523 |
|
| 524 |
case 'eDeposit':
|
| 525 |
$somearray['setting'] = variable_get('uc_setcom_edeposit', 0);
|
| 526 |
list($output, $somestring) = uc_setcom_check_trans($somearray, $somestring);
|
| 527 |
break;
|
| 528 |
|
| 529 |
default:
|
| 530 |
$somearray['setting'] = 3;
|
| 531 |
list($output, $somestring) = uc_setcom_check_trans($somearray, $somestring);
|
| 532 |
break;
|
| 533 |
}
|
| 534 |
if ($pmt_type != 'Credit Card' && $somearray['setting'] != 2) {
|
| 535 |
foreach ($order_synchro->outcome->order->alerts->alert as $alerts) {
|
| 536 |
$somestring .= '<br><br><u>Transaction notification from <strong>SETCOM</strong>: </u><fieldset>'. $alerts->text .'<br></fieldset><br>';
|
| 537 |
}
|
| 538 |
}
|
| 539 |
if ($somestring) {
|
| 540 |
drupal_set_message($somestring, 'status');
|
| 541 |
watchdog('Setcom', $somestring, array(), WATCHDOG_NOTICE);
|
| 542 |
}
|
| 543 |
} //end tnx successful
|
| 544 |
return $output;
|
| 545 |
}
|
| 546 |
else { // END - [if (empty($scurlerror))]
|
| 547 |
drupal_set_message(t('There was an error in the communication with Setcom. No confirmation reply from their server. ') , 'error');
|
| 548 |
if (variable_get('setcom_do_email', TRUE) == TRUE) {
|
| 549 |
drupal_set_message(t('<b>The store owner has been notified and will look into the problem.', 'error'));
|
| 550 |
uc_setcom_send_error('No Curl received', 'No Curl data was send from Setcom.');
|
| 551 |
}
|
| 552 |
watchdog('Setcom', $somestring, array(), WATCHDOG_NOTICE);
|
| 553 |
}
|
| 554 |
}
|
| 555 |
|
| 556 |
|
| 557 |
/******************************************************************************
|
| 558 |
* Helper Functions and Script
|
| 559 |
******************************************************************************/
|
| 560 |
|
| 561 |
/**
|
| 562 |
* helper function for transaction type.
|
| 563 |
*/
|
| 564 |
function uc_setcom_check_trans($somearray, $somestring) {
|
| 565 |
$order_check = uc_order_load($somearray['order']);
|
| 566 |
|
| 567 |
switch ($somearray['setting']) {
|
| 568 |
|
| 569 |
case 0:
|
| 570 |
$output = uc_cart_complete_sale($order_check, variable_get('uc_new_customer_login', FALSE));
|
| 571 |
uc_order_comment_save($order_check->order_id, 0, $somestring);
|
| 572 |
uc_payment_enter($order_check->order_id, 'Setcom', $somearray['tnx_amount'], 0, NULL, $somestring);
|
| 573 |
ca_pull_trigger('setcom_payment_received', $order_check, $user->uid == 0 ? $account : $user);
|
| 574 |
break;
|
| 575 |
|
| 576 |
case 1:
|
| 577 |
$somestring .= t('<strong>Order will only ship when funds clear in our bank account.</strong>');
|
| 578 |
$output = uc_cart_complete_sale($order_check, variable_get('uc_new_customer_login', FALSE));
|
| 579 |
uc_order_comment_save($order_check->order_id, 0, $somestring);
|
| 580 |
ca_pull_trigger('setcom_payment_pending', $order_check, $user->uid == 0 ? $account : $user);
|
| 581 |
break;
|
| 582 |
|
| 583 |
case 2:
|
| 584 |
$somestring = t('<strong>We do not accept payment via '. $somearray['pmt_type'] .'.</strong><br> We can not honour payment for this order.<br> If you have already made a payment, please contact Setcom to reverse this payment.<br> You can do a checkout the order again and select a different method of payment on the Setcom page.<br>');
|
| 585 |
$somestring .= uc_setcom_get_details();
|
| 586 |
|
| 587 |
if (variable_get('setcom_do_email', TRUE) == TRUE) {
|
| 588 |
uc_setcom_send_error(t('Payment method not allowed', 'Customer tried to buy with '. $somearray['pmt_type'] .', a payment method that is not allowed. Order no.:'. $order_check->order_id .' Order user ID:'. $order_check->uid));
|
| 589 |
}
|
| 590 |
drupal_set_message($somestring, 'error');
|
| 591 |
watchdog('Setcom', $somestring, array(), WATCHDOG_NOTICE);
|
| 592 |
$output ='<a href="'. url() .'">Click to return to the front page.</a>';
|
| 593 |
$somestring = '';
|
| 594 |
ca_pull_trigger('setcom_payment_denied', $order_check, $user->uid == 0 ? $account : $user);
|
| 595 |
break;
|
| 596 |
|
| 597 |
case 3:
|
| 598 |
default:
|
| 599 |
$somestring .= '<br>'. t('Even though the transaction is successful, there was an error in that we could not determine which payment method was used in this transaction.');
|
| 600 |
|
| 601 |
if (variable_get('setcom_do_email', TRUE) == TRUE) {
|
| 602 |
$somestring .= t('<br>The store owner has been notified and will look into the problem.');
|
| 603 |
uc_setcom_send_error('Transaction method error', 'Transaction method could not be determined. Contact Setcom regarding this problem. The order was not processed (stay Pending). Order no.:'. $order_check->order_id .' Order user ID:'. $order_check->uid);
|
| 604 |
}
|
| 605 |
watchdog('Setcom', $somestring, array(), WATCHDOG_NOTICE);
|
| 606 |
$output ='<a href="'. url() .'">Click to return to the front page.</a>';
|
| 607 |
uc_order_comment_save($order_check->order_id, 0, $somestring);
|
| 608 |
break;
|
| 609 |
|
| 610 |
}
|
| 611 |
return array($output, $somestring);
|
| 612 |
}
|
| 613 |
|
| 614 |
/**
|
| 615 |
* helper function for payment type details.
|
| 616 |
*/
|
| 617 |
function uc_setcom_get_details() {
|
| 618 |
$is_allowed=array();
|
| 619 |
$is_allowed_wait=array();
|
| 620 |
$not_allowed=array();
|
| 621 |
|
| 622 |
if (variable_get('uc_setcom_credit_card', 0)==0) {
|
| 623 |
$is_allowed[] ='Credit Card';
|
| 624 |
}
|
| 625 |
elseif (variable_get('uc_setcom_credit_card', 0)==1) {
|
| 626 |
$is_allowed_wait[] = ' Credit Card';
|
| 627 |
}
|
| 628 |
else {
|
| 629 |
$not_allowed[] =' Credit Card';
|
| 630 |
}
|
| 631 |
|
| 632 |
if (variable_get('uc_setcom_poli', 0)==0) {
|
| 633 |
$is_allowed[] =' POLi/SID';
|
| 634 |
}
|
| 635 |
elseif (variable_get('uc_setcom_credit_poli', 0)==1) {
|
| 636 |
$is_allowed_wait[] = ' POLi/SID';
|
| 637 |
}
|
| 638 |
else {
|
| 639 |
$not_allowed[] =' POLi/SID';
|
| 640 |
}
|
| 641 |
|
| 642 |
if (variable_get('uc_setcom_balance', 0)==0) {
|
| 643 |
$is_allowed[] =' Setcom Balance';
|
| 644 |
}
|
| 645 |
elseif (variable_get('uc_setcom_balance', 0)==1) {
|
| 646 |
$is_allowed_wait[] = ' Setcom Balance';
|
| 647 |
}
|
| 648 |
else {
|
| 649 |
$not_allowed[] =' Setcom Balance';
|
| 650 |
}
|
| 651 |
|
| 652 |
if (variable_get('uc_setcom_echeque', 0)==0) {
|
| 653 |
$is_allowed[] =' eCheque';
|
| 654 |
}
|
| 655 |
elseif (variable_get('uc_setcom_echeque', 0)==1) {
|
| 656 |
$is_allowed_wait[] = ' eCheque';
|
| 657 |
}
|
| 658 |
else {
|
| 659 |
$not_allowed[] =' eCheque';
|
| 660 |
}
|
| 661 |
|
| 662 |
if (variable_get('uc_setcom_edeposit', 0)==0) {
|
| 663 |
$is_allowed[] =' eDeposit';
|
| 664 |
}
|
| 665 |
elseif (variable_get('uc_setcom_edeposit', 0)==1) {
|
| 666 |
$is_allowed_wait[] = ' eDeposit';
|
| 667 |
}
|
| 668 |
else {
|
| 669 |
$not_allowed[] = ' eDeposit';
|
| 670 |
}
|
| 671 |
|
| 672 |
$details = t('<u><h4>Setcom offers a variety of payment methods. The following conditions apply to this shop:</h4> </u>');
|
| 673 |
|
| 674 |
if ($is_allowed) {
|
| 675 |
$details .= t('<u>Accepted payment methods that clear and dispatch immediate: </u><br>') . implode(", ", $is_allowed) .'.<br>';
|
| 676 |
}
|
| 677 |
if ($is_allowed_wait) {
|
| 678 |
$details .= t('<u>Accepted payment methods that clear after a few days and will be dispatched only when payment received: </u><br>') . implode(", ", $is_allowed_wait) .'.<br>';
|
| 679 |
}
|
| 680 |
if ($not_allowed) {
|
| 681 |
$details .= t('<u>These payment methods are not accepted. Order will not be honoured should you use them: </u><br>') . implode(", ", $not_allowed) .'.<br>';
|
| 682 |
}
|
| 683 |
return $details;
|
| 684 |
}
|
| 685 |
|
| 686 |
/**
|
| 687 |
* helper function for error email.
|
| 688 |
*/
|
| 689 |
function uc_setcom_send_error($subject, $body) {
|
| 690 |
$mail_to = variable_get('setcom_error_email', variable_get('site_mail', ini_get('sendmail_from')));
|
| 691 |
// drupal_mail('setcom_error', $mail_to, $subject, $body, $mail_to);
|
| 692 |
/* TODO Create a hook_mail($key, &$message, $params) function to generate
|
| 693 |
the message body when called by drupal_mail. */
|
| 694 |
$account = array(); // Set this as needed
|
| 695 |
$language = user_preferred_language($account);
|
| 696 |
$object = array(); // Replace this as needed
|
| 697 |
$context['subject'] = $subject;
|
| 698 |
$context['body'] = $body;
|
| 699 |
$params = array('account' => $account, 'object' => $object, 'context' => $context);
|
| 700 |
drupal_mail('uc_setcom', 'setcom_error', $mail_to, $language, $params, $mail_to);
|
| 701 |
}
|
| 702 |
|
| 703 |
/**
|
| 704 |
* Replacement function if wddx_deserialize does not exist.
|
| 705 |
*/
|
| 706 |
if (!function_exists('wddx_deserialize')) {
|
| 707 |
// Clone implementation of wddx_deserialize
|
| 708 |
function wddx_deserialize($xmlpacket) {
|
| 709 |
if ($xmlpacket instanceof SimpleXMLElement) {
|
| 710 |
if (!empty($xmlpacket->struct)) {
|
| 711 |
$struct = array();
|
| 712 |
foreach ($xmlpacket->xpath("struct/var") as $var) {
|
| 713 |
if (!empty($var["name"])) {
|
| 714 |
$key = (string) $var["name"];
|
| 715 |
$struct[$key] = wddx_deserialize($var);
|
| 716 |
}
|
| 717 |
}
|
| 718 |
return $struct;
|
| 719 |
}
|
| 720 |
else if (!empty($xmlpacket->array)) { //jEdit php parser thinks this is an error, maybe because of the use of 'array' name as an object variable?
|
| 721 |
$array = array();
|
| 722 |
foreach ($xmlpacket->xpath("array/*") as $var) {
|
| 723 |
array_push($array, wddx_deserialize($var));
|
| 724 |
}
|
| 725 |
return $array;
|
| 726 |
}
|
| 727 |
else if (!empty($xmlpacket->string)) {
|
| 728 |
return (string) $xmlpacket->string;
|
| 729 |
}
|
| 730 |
else if (!empty($xmlpacket->number)) {
|
| 731 |
return (int) $xmlpacket->number;
|
| 732 |
}
|
| 733 |
else {
|
| 734 |
if (is_numeric((string) $xmlpacket)) {
|
| 735 |
return (int) $xmlpacket;
|
| 736 |
}
|
| 737 |
else {
|
| 738 |
return (string) $xmlpacket;
|
| 739 |
}
|
| 740 |
}
|
| 741 |
}
|
| 742 |
else {
|
| 743 |
$sxe = simplexml_load_string($xmlpacket);
|
| 744 |
$datanode = $sxe->xpath("/wddxPacket[@version='1.0']/data");
|
| 745 |
return wddx_deserialize($datanode[0]);
|
| 746 |
}
|
| 747 |
}
|
| 748 |
}
|
| 749 |
|
| 750 |
/**
|
| 751 |
* Reformat amount values
|
| 752 |
**/
|
| 753 |
function getcurrency($amt, $cur) {
|
| 754 |
if (strlen($cur) > 0) {
|
| 755 |
switch (strtoupper($cur)) {
|
| 756 |
|
| 757 |
case 'ZAR' :
|
| 758 |
$cur_sym = 'R';
|
| 759 |
break;
|
| 760 |
|
| 761 |
case 'GBP' :
|
| 762 |
$cur_sym = '�';
|
| 763 |
break;
|
| 764 |
|
| 765 |
case 'USD' :
|
| 766 |
$cur_sym = '$';
|
| 767 |
break;
|
| 768 |
|
| 769 |
case 'EUR' :
|
| 770 |
$cur_sym = 'E';
|
| 771 |
break;
|
| 772 |
|
| 773 |
default:
|
| 774 |
$cur_sym = '';
|
| 775 |
}
|
| 776 |
}
|
| 777 |
else {
|
| 778 |
$cur_sym = '';
|
| 779 |
}
|
| 780 |
if ($amt < 0) {
|
| 781 |
$amt=abs($amt);
|
| 782 |
$new_amt = '-'. $cur_sym . number_format(($amt / 100), 2, '.', '');
|
| 783 |
}
|
| 784 |
else {
|
| 785 |
$new_amt = $cur_sym . number_format(($amt / 100), 2, '.', '');
|
| 786 |
}
|
| 787 |
return $new_amt;
|
| 788 |
}
|