Skip to content

Commit

Permalink
Merge pull request #2 from pagantis/new_features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
romeritoCL authored Feb 24, 2020
2 parents 485606d + e839d35 commit e73dcd6
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 78 deletions.
28 changes: 0 additions & 28 deletions commerce_pagamastarde/README.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Paga+Tarde module for DrupalCommerce 2.x with Drupal 7.x., 2015-11-24
Pagantis module for DrupalCommerce 2.x with Drupal 7.x., 2015-11-24
------------------------------------------------------------------
First public release

24 changes: 24 additions & 0 deletions commerce_pagantis/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Pagantis (https://www.pagantis.com/ ) module allows your DrupalCommerce
shop to offer financing payments.


Configuration
-------------

This payment module may be added and configured via the normal Rules interface.


Pagantis account settings
------------------------------

Once installed you only have to fill the account details you have in the
https://bo.pagantis.com/users/sing_up
For more information read the Guide.pdf provided with the module.

Troubleshooting
---------------
For any problems, doubts or questions, please contact us at integrations@pagantis.com

Credits
-------
This module is based on a Authorize.net SIM-only implementation.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = Paga+Tarde
description = Implements Paga+Tarde financing payment services for use with Drupal Commerce.
name = Pagantis
description = Pagantis financing payment services for use with Drupal Commerce.
package = Commerce (contrib)
files[] = commerce_pagamastarde.module
files[] = commerce_pagantis.module
dependencies[] = commerce
dependencies[] = commerce_ui
dependencies[] = commerce_payment
Expand All @@ -11,5 +11,5 @@ core = 7.x
; Information added by Drupal.org packaging script on 2015-08-31
version = "7.x-2.3"
core = "7.x"
project = "commerce_pagamastarde"
project = "commerce_pagantis"
datestamp = "1448220055"
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

/**
* @file
* Implements Paga+Tarde payment services for use with Drupal Commerce.
* Implements Pagantis payment services for use with Drupal Commerce.
*/

/**
* Paga+Tarde server addresses.
* Pagantis server addresses.
*/
define('COMMERCE_PAGAMASTARDE_PAGAMASTARDE_URL', 'https://pmt.pagantis.com/v1/installments');
define('commerce_pagantis_PAGAMASTARDE_URL', 'https://pmt.pagantis.com/v1/installments');

/**
* Implements hook_menu().
*/
function commerce_pagamastarde_menu() {
function commerce_pagantis_menu() {
$items = array();

$items['cart/pagamastarde/complete'] = array(
'title' => 'Order complete using Paga+Tarde',
'page callback' => 'commerce_pagamastarde_complete',
$items['cart/pagantis/complete'] = array(
'title' => 'Order complete using Pagantis',
'page callback' => 'commerce_pagantis_complete',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['cart/pagamastarde/order_complete'] = array(
'title' => 'User Redirect after order complete using Paga+Tarde',
'page callback' => 'commerce_pagamastarde_order_complete',
$items['cart/pagantis/order_complete'] = array(
'title' => 'User Redirect after order complete using Pagantis',
'page callback' => 'commerce_pagantis_order_complete',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
Expand All @@ -35,14 +35,14 @@ function commerce_pagamastarde_menu() {
/**
* Implements hook_commerce_payment_method_info().
*/
function commerce_pagamastarde_commerce_payment_method_info() {
function commerce_pagantis_commerce_payment_method_info() {
$payment_methods = array();

$payment_methods['pagamastarde'] = array(
'base' => 'commerce_pagamastarde',
'title' => t('Financiación con Paga+Tarde'),
'short_title' => t('Paga+Tarde'),
'description' => t('Paga+Tarde'),
$payment_methods['pagantis'] = array(
'base' => 'commerce_pagantis',
'title' => t('Financiación con Pagantis'),
'short_title' => t('Pagantis'),
'description' => t('Pagantis'),
'active' => FALSE,
'terminal' => FALSE,
'offsite' => TRUE,
Expand All @@ -55,7 +55,7 @@ function commerce_pagamastarde_commerce_payment_method_info() {
/**
* Payment method callback: settings form.
*/
function commerce_pagamastarde_settings_form($settings = NULL) {
function commerce_pagantis_settings_form($settings = NULL) {
$form = array();

$settings = (array) $settings + array(
Expand Down Expand Up @@ -109,7 +109,7 @@ function commerce_pagamastarde_settings_form($settings = NULL) {
'true' => t('true'),
),
'#multiple' => FALSE,
'#description' => t('True si quieres asumir las comisiones de Paga+Tarde, false si quieres que el cliente asuma las comisiones.'),
'#description' => t('True si quieres asumir las comisiones de Pagantis, false si quieres que el cliente asuma las comisiones.'),
'#default_value' => $settings['discount'],
);
return $form;
Expand All @@ -118,16 +118,26 @@ function commerce_pagamastarde_settings_form($settings = NULL) {
/**
* Redirect form, a wrapper function for building a form.
*/
function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payment_method) {
function commerce_pagantis_redirect_form($form, &$form_state, $order, $payment_method) {
// Return an error if the enabling action's settings haven't been configured.
if (empty($payment_method['settings']['test_account']) || empty($payment_method['settings']['test_key'])) {
drupal_set_message(t('Paga+Tarde is not configured for use. No account credentials have been specified.'), 'error');
drupal_set_message(t('Pagantis is not configured for use. No account credentials have been specified.'), 'error');
return array();
}

$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$currency_code = $order_wrapper->commerce_order_total->currency_code->value();

$currency = commerce_currency_load($currency_code);
$divisor = 1;
switch ((int) $currency['decimals']) {
case 3:
$divisor = 10;
case 4:
$divisor = 100;
}

// Build a description for the order.
// Build a description for the order.
$description = array();
$i = 1;
foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
Expand All @@ -139,7 +149,7 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
// Item descriptions.
$items["items[$i][description]"] = $product->title . " (" . $line_item_wrapper->quantity->value() . ")";
$items["items[$i][quantity]"] = $line_item_wrapper->quantity->value();
$items["items[$i][amount]"] = number_format($price['amount'] / 100 * $line_item_wrapper->quantity->value(), 2, ',', '');
$items["items[$i][amount]"] = (string) (($price['amount'] / $divisor) * $line_item_wrapper->quantity->value());
$i++;
}

Expand All @@ -149,11 +159,11 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
// Shipping data.
$items["items[0][description]"] = $line_item_wrapper->value()->data['shipping_service']['name'];
$items["items[0][quantity]"] = 1;
$items["items[0][amount]"] += $line_item_wrapper->value()->data['shipping_service']['base_rate']['amount'] / 100;
$items["items[0][amount]"] += $line_item_wrapper->value()->data['shipping_service']['base_rate']['amount'] / $divisor;
}
}

$items["items[0][amount]"] = number_format($items["items[0][amount]"], 2, ',', '');
$items["items[0][amount]"] = (string) $items["items[0][amount]"];

// Prepare the billing address for use in the request.
$billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value();
Expand All @@ -169,9 +179,7 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
$shipping_address['last_name'] = implode(' ', $name_parts);
}

$amount = $order_wrapper->commerce_order_total->amount->value();
$currency_code = $order_wrapper->commerce_order_total->currency_code->value();

$amount = (string) floor($order_wrapper->commerce_order_total->amount->value() / $divisor);
if ($payment_method['settings']['entorno'] == 'test') {
$the_account = $payment_method['settings']['test_account'];
$the_key = $payment_method['settings']['test_key'];
Expand All @@ -180,19 +188,18 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
$the_account = $payment_method['settings']['real_account'];
$the_key = $payment_method['settings']['real_key'];
}
$amount = $amount;

$args = array(
'oid' => $order->order_id ,
);

$ok_url = url('cart/pagamastarde/order_complete', array('absolute' => TRUE, 'query' => $args));
$ok_url = url('cart/pagantis/order_complete', array('absolute' => TRUE, 'query' => $args));

$args = array(
'pid' => $payment_method['instance_id']
);

$callback_url = check_url(url('cart/pagamastarde/complete', array('absolute' => TRUE, 'query' => $args)));
$callback_url = check_url(url('cart/pagantis/complete', array('absolute' => TRUE, 'query' => $args)));
$cancelled_url = check_url(url('checkout/' . $order->order_id . '/payment/back/' . $order->data['payment_redirect_key'], array('absolute' => TRUE)));
$nok_url = check_url(url('checkout/' . $order->order_id . '/payment/back/' . $order->data['payment_redirect_key'], array('absolute' => TRUE)));

Expand All @@ -202,8 +209,8 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
$signature = sha1($message);
$signature = hash('sha512',$message);

$state_code = commerce_pagamastarde_get_state_name($billing_address['administrative_area'], $billing_address['country']);
$sstate_code = commerce_pagamastarde_get_state_name($shipping_address['administrative_area'], $shipping_address['country']);
$state_code = commerce_pagantis_get_state_name($billing_address['administrative_area'], $billing_address['country']);
$sstate_code = commerce_pagantis_get_state_name($shipping_address['administrative_area'], $shipping_address['country']);

$submit_data = array(
'order_id' => $order->order_id,
Expand Down Expand Up @@ -232,7 +239,7 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
$submit_data[$key] = $value;
}

$form['#action'] = COMMERCE_PAGAMASTARDE_PAGAMASTARDE_URL;
$form['#action'] = commerce_pagantis_PAGAMASTARDE_URL;

foreach ($submit_data as $name => $value) {
$form[$name] = array(
Expand All @@ -247,7 +254,7 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme

$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => 'Financiación con Paga+Tarde',
'#value' => 'Financiación con Pagantis',
);

$form['actions']['cancel'] = array(
Expand All @@ -260,11 +267,11 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
),
'#attached' => array(
'js' => array(
'https://cdn.pagamastarde.com/pmt-simulator/3/js/pmt-simulator.min.js',
'https://cdn.pagantis.com/pmt-simulator/3/js/pmt-simulator.min.js',
array
(
'type' => 'inline',
'data' => 'jQuery(document).ready(function(){jQuery("#commerce-pagamastarde-redirect-form").submit();});',
'data' => 'jQuery(document).ready(function(){jQuery("#commerce-pagantis-redirect-form").submit();});',
)
),
),
Expand All @@ -277,9 +284,9 @@ function commerce_pagamastarde_redirect_form($form, &$form_state, $order, $payme
}

/**
* Callback function for posted Paga+Tarde payment response.
* Callback function for posted Pagantis payment response.
*/
function commerce_pagamastarde_complete() {
function commerce_pagantis_complete() {
$json = file_get_contents('php://input');

$notification = json_decode($json, TRUE);
Expand Down Expand Up @@ -307,9 +314,9 @@ function commerce_pagamastarde_complete() {

$currency_code = $order_wrapper->commerce_order_total->currency_code->value();

$transaction = commerce_payment_transaction_new('pagamastarde', $order->order_id);
$transaction = commerce_payment_transaction_new('pagantis', $order->order_id);
$transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
$transaction->message = "Paga+Tarde payment received for order: " . $order->order_id;
$transaction->message = "Pagantis payment received for order: " . $order->order_id;
$transaction->remote_id = $notification['data']['id'];
$transaction->amount = commerce_currency_decimal_to_amount($notification['data']['amount'] / 100, $notification['data']['currency']);
$transaction->currency_code = $currency_code;
Expand All @@ -320,7 +327,7 @@ function commerce_pagamastarde_complete() {
$args = array(
'oid' => $order_id,
);
$redirect_url = url('cart/pagamastarde/order_complete', array('absolute' => TRUE, 'query' => $args));
$redirect_url = url('cart/pagantis/order_complete', array('absolute' => TRUE, 'query' => $args));

$output = "<html><head><title>Processing Payment</title><script language=\"javascript\">\n";
$output .= "<!--\n";
Expand All @@ -339,12 +346,12 @@ function commerce_pagamastarde_complete() {
}

/**
* Callback function triggered by Paga+Tarde.
* Callback function triggered by Pagantis.
* Implements hook_order_complete
*/
function commerce_pagamastarde_order_complete() {
function commerce_pagantis_order_complete() {
$order_id = $_GET['oid'];
watchdog('commerce_pagamastarde', 'Receiving redirect response for order !order_id from Paga+Tarde', array('!order_id' => $order_id));
watchdog('commerce_pagantis', 'Receiving redirect response for order !order_id from Pagantis', array('!order_id' => $order_id));

// Validate posted data.
if ($order = commerce_order_load($order_id)) {
Expand All @@ -359,7 +366,7 @@ function commerce_pagamastarde_order_complete() {
/**
* Returns a state name given a state code.
*/
function commerce_pagamastarde_get_state_name($state_code, $country_code = NULL) {
function commerce_pagantis_get_state_name($state_code, $country_code = NULL) {
if ($state_code) {
$state_code = drupal_strtoupper($state_code);
$country_code = $country_code ? drupal_strtoupper($country_code) : 'US';
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# user and password for admin: drupal
version: '3.7'
services:
drupal:
container_name: drupal
image: 8thom/commerce-kickstart
ports:
- 9095:80
volumes:
- ./commerce_pagantis:/var/www/html/sites/all/modules/commerce_pagantis
extra_hosts:
- "drupal.docker:127.0.0.1"
Binary file removed releases/commerce_pagamastarde-1.0.1.zip
Binary file not shown.
Binary file removed releases/commerce_pagamastarde-7.x-1.3-rc1.zip
Binary file not shown.
Binary file removed releases/commerce_pagamastarde-7.x-1.x.zip
Binary file not shown.

0 comments on commit e73dcd6

Please sign in to comment.