updated ubercart, faq

This commit is contained in:
Bachir Soussi Chiadmi
2016-11-05 16:50:18 +01:00
parent 3413d81bb8
commit 0bb339fc99
110 changed files with 1382 additions and 641 deletions

View File

@@ -4,9 +4,9 @@ dependencies[] = uc_payment
package = Ubercart - payment
core = 7.x
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -9,9 +9,18 @@
* Implements hook_uninstall().
*/
function uc_2checkout_uninstall() {
db_delete('variable')
->condition('name', 'uc_2checkout_%', 'LIKE')
->execute();
// Remove all module variables from the database.
variable_del('uc_2checkout_check');
variable_del('uc_2checkout_checkout_type');
variable_del('uc_2checkout_currency_code');
variable_del('uc_2checkout_demo');
variable_del('uc_2checkout_language');
variable_del('uc_2checkout_notification_url');
variable_del('uc_2checkout_method_title');
variable_del('uc_2checkout_secret_word');
variable_del('uc_2checkout_server_url');
variable_del('uc_2checkout_sid');
}
/**

View File

@@ -31,6 +31,11 @@ function uc_2checkout_menu() {
'type' => MENU_CALLBACK,
'file' => 'uc_2checkout.pages.inc',
);
$items['cart/2checkout/notification'] = array(
'page callback' => 'uc_2checkout_process_notification',
'access callback' => TRUE,
'file' => 'uc_2checkout.pages.inc',
);
return $items;
}
@@ -143,6 +148,15 @@ function uc_payment_method_2checkout($op, &$order, $form = NULL, &$form_state =
),
'#default_value' => variable_get('uc_2checkout_language', 'en'),
);
$form['uc_2checkout_currency_code'] = array(
'#type' => 'select',
'#title' => t('Currency for the sale'),
'#options' => array(
'' => t('Auto detected by 2CO'),
'USD', 'EUR', 'ARS', 'AUD', 'BRL', 'GBP', 'CAD', 'DKK', 'HKD', 'INR', 'ILS', 'JPY', 'LTL', 'MYR', 'MXN', 'NZD', 'NOK', 'PHP', 'RON', 'RUB', 'SGD', 'ZAR', 'SEK', 'CHF', 'TRY', 'AED'
),
'#default_value' => variable_get('uc_2checkout_currency_code', ''),
);
$form['uc_2checkout_check'] = array(
'#type' => 'checkbox',
'#title' => t('Allow customers to choose to pay by credit card or online check.'),
@@ -154,14 +168,20 @@ function uc_payment_method_2checkout($op, &$order, $form = NULL, &$form_state =
'#default_value' => variable_get('uc_2checkout_method_title', t('Credit card on a secure server:')),
);
$form['uc_2checkout_checkout_type'] = array(
'#type' => 'select',
'#title' => t('2Checkout.com checkout type'),
'#description' => t('Single page checkout only works for stores selling intangible products using credit card payments.'),
'#type' => 'radios',
'#title' => t('Checkout type'),
'#options' => array(
'multi' => t('Multi-page checkout'),
'single' => t('Single page checkout'),
'dynamic' => t('Dynamic checkout (user is redirected to 2CO)'),
'direct' => t('Direct checkout (payment page opens in iframe popup)'),
),
'#default_value' => variable_get('uc_2checkout_checkout_type', 'multi'),
'#default_value' => variable_get('uc_2checkout_checkout_type', 'dynamic'),
);
$form['uc_2checkout_notification_url'] = array(
'#type' => 'textfield',
'#title' => t('Instant notification settings URL'),
'#description' => t('Pass this URL to the <a href="@help_url">instant notification settings</a> parameter in your 2Checkout account. This way, any refunds or failed fraud reviews will automatically cancel the Ubercart order.', array('@help_url' => 'https://www.2checkout.com/static/va/documentation/INS/index.html')),
'#default_value' => url('cart/2checkout/notification', array('absolute' => TRUE)),
'#attributes' => array('readonly' => 'readonly'),
);
return $form;
}
@@ -178,14 +198,7 @@ function uc_2checkout_form($form, &$form_state, $order) {
$data = array(
'sid' => variable_get('uc_2checkout_sid', ''),
'total' => uc_currency_format($order->order_total, FALSE, FALSE, '.'),
'cart_order_id' => $order->order_id,
'demo' => variable_get('uc_2checkout_demo', TRUE) ? 'Y' : 'N',
'fixed' => 'Y',
'lang' => variable_get('uc_2checkout_language', 'en'),
'x_receipt_link_url' => url('cart/2checkout/complete/' . uc_cart_get_id(), array('absolute' => TRUE)),
'merchant_order_id' => $order->order_id,
'pay_method' => isset($_SESSION['pay_method']) ? $_SESSION['pay_method'] : 'CC',
'mode' => '2CO',
'card_holder_name' => drupal_substr($order->billing_first_name . ' ' . $order->billing_last_name, 0, 128),
'street_address' => drupal_substr($order->billing_street1, 0, 64),
'street_address2' => drupal_substr($order->billing_street2, 0, 64),
@@ -195,19 +208,34 @@ function uc_2checkout_form($form, &$form_state, $order) {
'country' => $country[0]['country_iso_code_3'],
'email' => drupal_substr($order->primary_email, 0, 64),
'phone' => drupal_substr($order->billing_phone, 0, 16),
'id_type' => 1,
'purchase_step' => 'payment-method',
'demo' => variable_get('uc_2checkout_demo', TRUE) ? 'Y' : 'N',
'lang' => variable_get('uc_2checkout_language', 'en'),
'merchant_order_id' => $order->order_id,
'pay_method' => 'CC',
'x_receipt_link_url' => url('cart/2checkout/complete/' . uc_cart_get_id(), array('absolute' => TRUE)),
'total' => uc_currency_format($order->order_total, FALSE, FALSE, '.'),
'cart_order_id' => $order->order_id,
);
if ($currency_code = variable_get('uc_2checkout_currency_code', '')) {
$data['currency_code'] = $currency_code;
}
$i = 0;
foreach ($order->products as $product) {
$i++;
$data['c_prod_' . $i] = $product->model . ',' . $product->qty;
$data['c_name_' . $i] = $product->title;
$data['c_description_' . $i] = '';
$data['c_price_' . $i] = uc_currency_format($product->price, FALSE, FALSE, '.');
$data['li_' . $i . '_name'] = $product->title;
$data['li_' . $i . '_price'] = uc_currency_format($product->price, FALSE, FALSE, '.');
}
$form['#action'] = _uc_2checkout_post_url(variable_get('uc_2checkout_checkout_type', 'multi'));
if (variable_get('uc_2checkout_checkout_type', 'dynamic') == 'direct') {
$form['#suffix'] = '<script src="https://www.2checkout.com/static/checkout/javascript/direct.min.js"></script>';
}
$form['#action'] = variable_get('uc_2checkout_server_url', 'https://www.2checkout.com/checkout/purchase');
foreach ($data as $name => $value) {
$form[$name] = array('#type' => 'hidden', '#value' => $value);
@@ -221,16 +249,3 @@ function uc_2checkout_form($form, &$form_state, $order) {
return $form;
}
/**
* Helper function to obtain 2Checkout URL for a transaction.
*/
function _uc_2checkout_post_url($type) {
switch ($type) {
case 'single':
return 'https://www.2checkout.com/checkout/spurchase';
case 'multi':
default:
return 'https://www.2checkout.com/2co/buyer/purchase';
}
}

View File

@@ -2,21 +2,20 @@
/**
* @file
* 2checkout menu items.
* 2Checkout menu items.
*/
/**
* Finalizes 2checkout transaction.
* Finalizes 2Checkout transaction.
*/
function uc_2checkout_complete($cart_id = 0) {
watchdog('2Checkout', 'Receiving new order notification for order !order_id.', array('!order_id' => check_plain($_REQUEST['merchant_order_id'])));
watchdog('uc_2checkout', 'Receiving new order notification for order !order_id.', array('!order_id' => check_plain($_REQUEST['merchant_order_id'])));
$order = uc_order_load($_REQUEST['merchant_order_id']);
if ($order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') {
if ($order === FALSE) {
return t('An error has occurred during payment. Please contact us to ensure your order has submitted.');
}
$key = $_REQUEST['key'];
$order_number = variable_get('uc_2checkout_demo', TRUE) ? 1 : $_REQUEST['order_number'];
$valid = md5(variable_get('uc_2checkout_secret_word', 'tango') . $_REQUEST['sid'] . $order_number . $_REQUEST['total']);
@@ -26,7 +25,7 @@ function uc_2checkout_complete($cart_id = 0) {
}
if ($_REQUEST['demo'] == 'Y' xor variable_get('uc_2checkout_demo', TRUE)) {
watchdog('uc_2checkout', 'The 2checkout payment for order <a href="@order_url">@order_id</a> demo flag was set to %flag, but the module is set to %mode mode.', array(
watchdog('uc_2checkout', 'The 2Checkout payment for order <a href="@order_url">@order_id</a> demo flag was set to %flag, but the module is set to %mode mode.', array(
'@order_url' => url('admin/store/orders/' . $order->order_id),
'@order_id' => $order->order_id,
'%flag' => $_REQUEST['demo'] == 'Y' ? 'Y' : 'N',
@@ -63,7 +62,7 @@ function uc_2checkout_complete($cart_id = 0) {
if ($_REQUEST['credit_card_processed'] == 'Y' && is_numeric($_REQUEST['total'])) {
$comment = t('Paid by !type, 2Checkout.com order #!order.', array('!type' => $_REQUEST['pay_method'] == 'CC' ? t('credit card') : t('echeck'), '!order' => check_plain($_REQUEST['order_number'])));
uc_payment_enter($order->order_id, '2checkout', $_REQUEST['total'], 0, NULL, $comment);
uc_payment_enter($order->order_id, '2Checkout', $_REQUEST['total'], 0, NULL, $comment);
}
else {
drupal_set_message(t('Your order will be processed as soon as your payment clears at 2Checkout.com.'));
@@ -86,3 +85,42 @@ function uc_2checkout_complete($cart_id = 0) {
return $build;
}
/**
* React on status changes from 2CO.
*/
function uc_2checkout_process_notification() {
$values = $_POST;
watchdog('uc_2checkout', 'Received 2Checkout notification with following data: !data', array('!data' => print_r($values, TRUE)));
if (!empty($values['message_type']) && !empty($values['md5_hash']) && !empty($values['message_id'])) {
// Validate the hash.
$secret_word = variable_get('uc_2checkout_secret_word', 'tango');
$sid = variable_get('uc_2checkout_sid', '');
$twocheckout_order_id = $values['sale_id'];
$twocheckout_invoice_id = $values['invoice_id'];
$hash = strtoupper(md5($twocheckout_order_id . $sid . $twocheckout_invoice_id . $secret_word));
if ($hash != $values['md5_hash']) {
watchdog('uc_2checkout', '2CO notification #@num had a wrong hash.', array('@num' => $values['message_id']));
die('Hash Incorrect');
}
$order_id = $values['vendor_order_id'];
if ($values['message_type'] == 'FRAUD_STATUS_CHANGED') {
switch ($values['fraud_status']) {
case 'fail':
uc_order_update_status($order_id, uc_order_state_default('canceled'));
uc_order_comment_save($order_id, 0, t('Order have not passed 2Checkout fraud review.'));
die('fraud');
break;
}
}
elseif ($values['message_type'] == 'REFUND_ISSUED') {
uc_order_update_status($order_id, uc_order_state_default('canceled'));
uc_order_comment_save($order_id, 0, t('Order have been refunded through 2Checkout.'));
die('refund');
}
}
die('ok');
}

View File

@@ -5,9 +5,9 @@ dependencies[] = uc_credit
package = Ubercart - payment
core = 7.x
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -5,9 +5,9 @@ dependencies[] = uc_credit
package = Ubercart - payment
core = 7.x
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -62,7 +62,7 @@ class UbercartCreditCardTestCase extends UbercartTestHelper {
/**
* Implements DrupalWebTestCase::setUp().
*/
public function setUp(array $modules = array()) {
protected function setUp($modules = array(), $permissions = array()) {
$modules += array('uc_payment', 'uc_credit', 'test_gateway');
$permissions = array('administer credit cards', 'process credit cards');
parent::setUp($modules, $permissions);

View File

@@ -8,9 +8,9 @@ core = 7.x
; Test cases
files[] = tests/uc_credit.test
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -7,9 +7,9 @@ core = 7.x
; Class definitions
files[] = uc_cybersource.soap.inc
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -6,9 +6,9 @@ dependencies[] = uc_quote
package = Ubercart - payment
core = 7.x
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -18,7 +18,7 @@ class UbercartPaymentPaneTestCase extends UbercartTestHelper {
/**
* Overrides DrupalWebTestCase::setUp().
*/
public function setUp() {
protected function setUp($modules = array(), $permissions = array()) {
parent::setUp(array('uc_payment', 'uc_payment_pack'));
$this->drupalLogin($this->adminUser);
$this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));

View File

@@ -0,0 +1,42 @@
/**
* @file
* Styles for uc_payment module.
*/
.payment-details-cod .form-item {
float: right;
padding-right: inherit;
padding-left: 5px;
}
.payment-details-credit label {
clear: right;
float: right;
}
.payment-details-credit input,
.payment-details-credit select {
float: right;
}
.payment-details-credit .field-suffix {
float: right;
}
img.uc-2checkout-logo {
left: auto;
right: 2.2em;
}
#line-items-div {
float: left;
margin: 0 1em 1em 0;
}
#uc-payment-by-order-form .form-type-item {
float: right;
}
#uc-payment-by-order-form table {
clear: right;
}

View File

@@ -107,7 +107,13 @@ function theme_uc_payment_method_table($variables) {
function uc_payment_method_settings_form($form, &$form_state, $method_id) {
$callback = _uc_payment_method_data($method_id, 'callback');
$null = NULL;
$form = $callback('settings', $null, array(), $form_state);
if (function_exists($callback)) {
$form = $callback('settings', $null, array(), $form_state);
}
else {
drupal_not_found();
drupal_exit();
}
return system_settings_form($form);
}

View File

@@ -21,8 +21,8 @@
.payment-details-cod .form-item {
display: block;
float: left;
padding-right: 5px;
float: left; /* LTR */
padding-right: 5px; /* LTR */
}
.payment-details-credit .form-item {
@@ -30,8 +30,8 @@
}
.payment-details-credit label {
clear: left;
float: left;
clear: left; /* LTR */
float: left; /* LTR */
margin: 2px 0;
padding-top: 5px;
width: 10em;
@@ -39,7 +39,7 @@
.payment-details-credit input,
.payment-details-credit select {
float: left;
float: left; /* LTR */
margin: 2px;
}
@@ -51,20 +51,20 @@
}
.payment-details-credit .field-suffix {
float: left;
float: left; /* LTR */
margin: 2px;
padding-top: 5px;
}
img.uc-2checkout-logo {
position: relative;
left: 2.2em;
left: 2.2em; /* LTR */
}
#line-items-div {
border: 1px solid #bbb;
float: right;
margin: 0 0 1em 1em;
float: right; /* LTR */
margin: 0 0 1em 1em; /* LTR */
}
#line-items-div table {
@@ -81,10 +81,10 @@ img.uc-2checkout-logo {
}
#uc-payment-by-order-form .form-type-item {
float: left;
float: left; /* LTR */
width: 10em;
}
#uc-payment-by-order-form table {
clear: left;
clear: left; /* LTR */
}

View File

@@ -10,9 +10,9 @@ files[] = tests/uc_payment.test
configure = admin/store/settings/payment
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -86,14 +86,19 @@ function uc_payment_schema() {
function uc_payment_install() {
$t = get_t();
db_insert('uc_order_statuses')
->fields(array(
db_merge('uc_order_statuses')
->key(array('order_status_id' => 'payment_received'))
->insertFields(array(
'order_status_id' => 'payment_received',
'title' => $t('Payment received'),
'state' => 'payment_received',
'weight' => 10,
'locked' => 1,
))
->updateFields(array(
'state' => 'payment_received',
'locked' => 1,
))
->execute();
}

View File

@@ -5,9 +5,9 @@ dependencies[] = uc_payment
package = Ubercart - payment
core = 7.x
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -4,9 +4,9 @@ dependencies[] = uc_payment
package = Ubercart - payment
core = 7.x
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -530,7 +530,7 @@ function uc_payment_method_paypal_ec($op, &$order) {
$form['api'] = array(
'#type' => 'fieldset',
'#title' => t('API credentials'),
'#description' => t('!link for information on obtaining credentials. You need to acquire an API Signature. If you have already requested API credentials, you can review your settings under the API Access section of your PayPal profile.', array('!link' => l(t('Click here'), 'https://www.paypal.com/IntegrationCenter/ic_certificate.html'))),
'#description' => t('!link for information on obtaining credentials. You need to acquire an API Signature. If you have already requested API credentials, you can review your settings under the API Access section of your PayPal profile.', array('!link' => l(t('Click here'), 'https://developer.paypal.com/docs/classic/api/apiCredentials/'))),
'#collapsible' => TRUE,
'#collapsed' => variable_get('uc_paypal_api_username', '') != '',
);