use foreign transaction rate for amex cards
This commit is contained in:
@@ -47,7 +47,7 @@ function booking_balance_page() {
|
|||||||
$tokens = booking_define_personspecific_tokens($node);
|
$tokens = booking_define_personspecific_tokens($node);
|
||||||
// @todo - use admin variable booking_payment_processor to determine which of these to calculate
|
// @todo - use admin variable booking_payment_processor to determine which of these to calculate
|
||||||
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
|
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
|
||||||
$tokens['stripe-total-form'] = _booking_stripe_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
|
$tokens['stripe-total-form'] = _booking_stripe_form($node, $invoiceid, $tokens['payment-required'], "Pay Balance");
|
||||||
|
|
||||||
//Calculate the amount outstanding
|
//Calculate the amount outstanding
|
||||||
//watchdog('booking', 'Booking Balance form calculating amount owing');
|
//watchdog('booking', 'Booking Balance form calculating amount owing');
|
||||||
|
@@ -34,12 +34,12 @@ function _booking_get_stripe_private_key() {
|
|||||||
/**
|
/**
|
||||||
* Helper function to generate paypal form for payments
|
* Helper function to generate paypal form for payments
|
||||||
*/
|
*/
|
||||||
function _booking_stripe_form($person, $invoiceid, $amount_owing, $button_text) {
|
function _booking_stripe_form($person, $invoiceid, $net_amount_owing, $button_text) {
|
||||||
$payment_form = drupal_get_form('booking_stripe_form', $person, $invoiceid, $amount_owing, $button_text);
|
$payment_form = drupal_get_form('booking_stripe_form', $person, $invoiceid, $amount_owing, $button_text);
|
||||||
return drupal_render($payment_form);
|
return drupal_render($payment_form);
|
||||||
}
|
}
|
||||||
|
|
||||||
function booking_stripe_form($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) {
|
function booking_stripe_form($node, &$form_state, $person, $invoiceid, $net_amount_owing, $button_text) {
|
||||||
global $event;
|
global $event;
|
||||||
$settings = array();
|
$settings = array();
|
||||||
$form = array();
|
$form = array();
|
||||||
@@ -51,7 +51,7 @@ function booking_stripe_form($node, &$form_state, $person, $invoiceid, $amount_o
|
|||||||
$setting['booking_stripe'] = array(
|
$setting['booking_stripe'] = array(
|
||||||
'pubkey' => _booking_get_stripe_public_key(),
|
'pubkey' => _booking_get_stripe_public_key(),
|
||||||
'form_selector' => str_replace('_', '-', __FUNCTION__),
|
'form_selector' => str_replace('_', '-', __FUNCTION__),
|
||||||
'name' => 'Study Week',
|
'name' => $event->booking_eventname,
|
||||||
'image' => '',
|
'image' => '',
|
||||||
);
|
);
|
||||||
//attach settings and javascript to the form
|
//attach settings and javascript to the form
|
||||||
@@ -63,38 +63,27 @@ function booking_stripe_form($node, &$form_state, $person, $invoiceid, $amount_o
|
|||||||
array('booking', 'booking-stripe'),
|
array('booking', 'booking-stripe'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
//paypal specific settings
|
//paypal specific settings
|
||||||
$vars = array(
|
$vars = array(
|
||||||
'module' => 'Booking System',
|
|
||||||
'type' => $event->booking_eventname,
|
|
||||||
'nid' => $person->nid,
|
'nid' => $person->nid,
|
||||||
'email' => $person->booking_email,
|
'email' => $person->booking_email,
|
||||||
'description' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
|
'description' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
|
||||||
'invoice' => $invoiceid,
|
'invoice' => $invoiceid,
|
||||||
'amount' => $amount_owing,
|
'amount' => $net_amount_owing,
|
||||||
|
'gross_amount' => _booking_add_stripe_fees($net_amount_owing, $person->booking_country),
|
||||||
|
'foreign_gross_amount' => _booking_add_stripe_fees($net_amount_owing, 'FakeCountry'),
|
||||||
'last_name' => $person->booking_lastname,
|
'last_name' => $person->booking_lastname,
|
||||||
'first_name' => $person->booking_firstname,
|
'first_name' => $person->booking_firstname,
|
||||||
'uuid' => $person->booking_tempid,
|
'uuid' => $person->booking_tempid,
|
||||||
'token_id' => '',
|
'token_id' => '',
|
||||||
'token_email' => ''
|
'token_email' => '',
|
||||||
|
'token_client_ip' => '',
|
||||||
|
'card_brand' => '',
|
||||||
|
'card_cvc_check' => '',
|
||||||
|
'card_address_zip_check' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
|
||||||
$form['#id'] = 'booking_stripe_form';
|
|
||||||
$form['#attached']['js'] = array(
|
|
||||||
array(
|
|
||||||
'data' => 'https://checkout.stripe.com/checkout.js',
|
|
||||||
'type' => 'external',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'data' => drupal_get_path('module', 'booking') . '/booking.stripe.js',
|
|
||||||
'type' => 'file',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
//turn the array into a form
|
//turn the array into a form
|
||||||
foreach($vars as $name => $value) {
|
foreach($vars as $name => $value) {
|
||||||
$form[$name] = array(
|
$form[$name] = array(
|
||||||
@@ -139,19 +128,19 @@ function booking_stripe_checkout_form_validate($form, &$form_state) {
|
|||||||
*/
|
*/
|
||||||
function booking_stripe_validate_form_payment($form, &$form_state) {
|
function booking_stripe_validate_form_payment($form, &$form_state) {
|
||||||
global $event;
|
global $event;
|
||||||
|
|
||||||
if($errors = form_get_errors()) {
|
if($errors = form_get_errors()) {
|
||||||
|
//@todo log an error via watchdog
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = libraries_get_path('stripe');
|
$path = libraries_get_path('stripe');
|
||||||
require_once($path . '/init.php');
|
require_once($path . '/init.php');
|
||||||
|
|
||||||
\Stripe\Stripe::setApiKey(_booking_get_stripe_private_key());
|
\Stripe\Stripe::setApiKey(_booking_get_stripe_private_key());
|
||||||
//$token = $form_state['values']['stripeToken'];
|
|
||||||
//$amount = $form_state['values']['amount'] * 100;
|
|
||||||
//get values from original form
|
//get values from original form
|
||||||
$token = (isset($form_state['input']['token_id']) ? $form_state['input']['token_id'] : '');
|
$token = (isset($form_state['input']['token_id']) ? $form_state['input']['token_id'] : '');
|
||||||
$amount = (isset($form_state['input']['amount']) ? $form_state['input']['amount'] : '');
|
$amount = (isset($form_state['input']['gross_amount']) ? $form_state['input']['gross_amount'] : '');
|
||||||
$invoice = (isset($form_state['input']['invoice']) ? $form_state['input']['invoice'] : '');
|
$invoice = (isset($form_state['input']['invoice']) ? $form_state['input']['invoice'] : '');
|
||||||
$nid = (isset($form_state['input']['nid']) ? $form_state['input']['nid'] : '');
|
$nid = (isset($form_state['input']['nid']) ? $form_state['input']['nid'] : '');
|
||||||
$tempid= (isset($form_state['input']['uuid']) ? $form_state['input']['uuid'] : '');
|
$tempid= (isset($form_state['input']['uuid']) ? $form_state['input']['uuid'] : '');
|
||||||
@@ -159,6 +148,16 @@ function booking_stripe_validate_form_payment($form, &$form_state) {
|
|||||||
$first_name = (isset($form_state['input']['first_name']) ? $form_state['input']['first_name'] : '');
|
$first_name = (isset($form_state['input']['first_name']) ? $form_state['input']['first_name'] : '');
|
||||||
watchdog('booking_debug', "<pre>Stripe token:\n@info</pre>", array('@info' => print_r( $token, true)));
|
watchdog('booking_debug', "<pre>Stripe token:\n@info</pre>", array('@info' => print_r( $token, true)));
|
||||||
|
|
||||||
|
//if card type is american express then the rate charged should be different
|
||||||
|
$card_type = (isset($form_state['input']['card_brand']) ? $form_state['input']['card_brand'] : '');
|
||||||
|
if ($card_type == 'American Express') {
|
||||||
|
//amount charged should be the international rate not the domestic rate
|
||||||
|
//@todo verify that nid is correct format
|
||||||
|
//@todo debug log to indicate price change
|
||||||
|
$person = node_load($nid);
|
||||||
|
$amount = (isset($form_state['input']['foreign_gross_amount']) ? $form_state['input']['foreign_gross_amount'] : $amount);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the charge on Stripe's servers - this will charge the user's card
|
// Create the charge on Stripe's servers - this will charge the user's card
|
||||||
try {
|
try {
|
||||||
$charge = \Stripe\Charge::create(array(
|
$charge = \Stripe\Charge::create(array(
|
||||||
|
@@ -1,16 +1,19 @@
|
|||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
var settings = Drupal.settings.booking_stripe;
|
var $settings = Drupal.settings.booking_stripe;
|
||||||
var $stripeForm = $("#" + settings.form_selector);
|
var $stripeForm = $("#" + $settings.form_selector);
|
||||||
var handler = StripeCheckout.configure({
|
var handler = StripeCheckout.configure({
|
||||||
key: settings.pubkey,
|
key: settings.pubkey,
|
||||||
image: settings.image,
|
image: settings.image,
|
||||||
locale: 'auto',
|
locale: 'auto',
|
||||||
token: function(token) {
|
token: function(token) {
|
||||||
try {
|
try {
|
||||||
// Use the token to create the charge with a server-side script.
|
//store the returned token into hidden form elements
|
||||||
// You can access the token ID with `token.id`
|
|
||||||
$(':input[name="token_id"]', $stripeForm).val(token.id);
|
$(':input[name="token_id"]', $stripeForm).val(token.id);
|
||||||
$(':input[name="token_email"]', $stripeForm).val(token.email);
|
$(':input[name="token_email"]', $stripeForm).val(token.email);
|
||||||
|
$(':input[name="token_client_ip"]', $stripeForm).val(token.client_ip);
|
||||||
|
$(':input[name="card_brand"]', $stripeForm).val(token.card.brand);
|
||||||
|
$(':input[name="card_cvc_check"]', $stripeForm).val(token.card.cvc_check);
|
||||||
|
$(':input[name="card_address_zip_check"]', $stripeForm).val(token.card.address_zip_check);
|
||||||
$stripeForm.get(0).submit();
|
$stripeForm.get(0).submit();
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
@@ -24,8 +27,8 @@ jQuery(document).ready(function($) {
|
|||||||
//currentForm = $(this).closest('form');
|
//currentForm = $(this).closest('form');
|
||||||
//if (currentForm === undefined)
|
//if (currentForm === undefined)
|
||||||
// return;
|
// return;
|
||||||
var settings = Drupal.settings.booking_stripe;
|
var $settings = Drupal.settings.booking_stripe;
|
||||||
var $stripeForm = $("#" + settings.form_selector);
|
var $stripeForm = $("#" + $settings.form_selector);
|
||||||
//$description = $(':input[name="description"]', $stripeForm).val();
|
//$description = $(':input[name="description"]', $stripeForm).val();
|
||||||
//console.log([$description]);
|
//console.log([$description]);
|
||||||
//description: currentForm.find('input[name="description"]').val(),
|
//description: currentForm.find('input[name="description"]').val(),
|
||||||
|
Reference in New Issue
Block a user