use foreign transaction rate for amex cards
This commit is contained in:
@@ -34,12 +34,12 @@ function _booking_get_stripe_private_key() {
|
||||
/**
|
||||
* 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);
|
||||
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;
|
||||
$settings = array();
|
||||
$form = array();
|
||||
@@ -51,7 +51,7 @@ function booking_stripe_form($node, &$form_state, $person, $invoiceid, $amount_o
|
||||
$setting['booking_stripe'] = array(
|
||||
'pubkey' => _booking_get_stripe_public_key(),
|
||||
'form_selector' => str_replace('_', '-', __FUNCTION__),
|
||||
'name' => 'Study Week',
|
||||
'name' => $event->booking_eventname,
|
||||
'image' => '',
|
||||
);
|
||||
//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'),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
//paypal specific settings
|
||||
$vars = array(
|
||||
'module' => 'Booking System',
|
||||
'type' => $event->booking_eventname,
|
||||
'nid' => $person->nid,
|
||||
'email' => $person->booking_email,
|
||||
'description' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
|
||||
'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,
|
||||
'first_name' => $person->booking_firstname,
|
||||
'uuid' => $person->booking_tempid,
|
||||
'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
|
||||
foreach($vars as $name => $value) {
|
||||
$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) {
|
||||
global $event;
|
||||
|
||||
if($errors = form_get_errors()) {
|
||||
//@todo log an error via watchdog
|
||||
return;
|
||||
}
|
||||
|
||||
$path = libraries_get_path('stripe');
|
||||
require_once($path . '/init.php');
|
||||
|
||||
\Stripe\Stripe::setApiKey(_booking_get_stripe_private_key());
|
||||
//$token = $form_state['values']['stripeToken'];
|
||||
//$amount = $form_state['values']['amount'] * 100;
|
||||
|
||||
//get values from original form
|
||||
$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'] : '');
|
||||
$nid = (isset($form_state['input']['nid']) ? $form_state['input']['nid'] : '');
|
||||
$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'] : '');
|
||||
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
|
||||
try {
|
||||
$charge = \Stripe\Charge::create(array(
|
||||
|
Reference in New Issue
Block a user