add country checking for stripe charges
This commit is contained in:
@@ -103,6 +103,7 @@ function booking_stripe_form($node, &$form_state, $person, $invoiceid, $net_amou
|
|||||||
'token_email' => '',
|
'token_email' => '',
|
||||||
'token_client_ip' => '',
|
'token_client_ip' => '',
|
||||||
'card_brand' => '',
|
'card_brand' => '',
|
||||||
|
'card_country' => '',
|
||||||
'card_cvc_check' => '',
|
'card_cvc_check' => '',
|
||||||
'card_address_zip_check' => '',
|
'card_address_zip_check' => '',
|
||||||
);
|
);
|
||||||
@@ -162,23 +163,30 @@ function booking_stripe_validate_form_payment($form, &$form_state) {
|
|||||||
\Stripe\Stripe::setApiKey(_booking_get_stripe_private_key());
|
\Stripe\Stripe::setApiKey(_booking_get_stripe_private_key());
|
||||||
|
|
||||||
//get values from original form
|
//get values from original form
|
||||||
|
//@todo sanitise this input
|
||||||
$token = (isset($form_state['input']['token_id']) ? $form_state['input']['token_id'] : '');
|
$token = (isset($form_state['input']['token_id']) ? $form_state['input']['token_id'] : '');
|
||||||
|
watchdog('booking_debug', "<pre>Stripe token:\n@info</pre>", array('@info' => print_r( $token, true)));
|
||||||
$amount = (isset($form_state['input']['gross_amount']) ? $form_state['input']['gross_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'] : '');
|
||||||
$last_name = (isset($form_state['input']['last_name']) ? $form_state['input']['last_name'] : '');
|
$last_name = (isset($form_state['input']['last_name']) ? $form_state['input']['last_name'] : '');
|
||||||
$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)));
|
$card_brand = (isset($form_state['input']['card_brand']) ? $form_state['input']['card_brand'] : '');
|
||||||
|
$card_country = (isset($form_state['input']['card_country']) ? $form_state['input']['card_country'] : '');
|
||||||
|
|
||||||
//if card type is american express then the rate charged should be different
|
//if card issuer is american express then the transaction fee charged should be the international rate
|
||||||
$card_type = (isset($form_state['input']['card_brand']) ? $form_state['input']['card_brand'] : '');
|
if ($card_brand == 'American Express') {
|
||||||
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);
|
$person = node_load($nid);
|
||||||
$amount = (isset($form_state['input']['foreign_gross_amount']) ? $form_state['input']['foreign_gross_amount'] : $amount);
|
$amount = (isset($form_state['input']['foreign_gross_amount']) ? $form_state['input']['foreign_gross_amount'] : $amount);
|
||||||
|
watchdog('booking_debug', "Detected Amex card use, setting amount to !amount", array('!amount' => $amount));
|
||||||
|
}
|
||||||
|
//if card is issued from a different country then apply the international rate also
|
||||||
|
elseif (variable_get('booking_default_country', 'Australia') == 'Australia' && $card_country != 'AU') {
|
||||||
|
$person = node_load($nid);
|
||||||
|
$amount = (isset($form_state['input']['foreign_gross_amount']) ? $form_state['input']['foreign_gross_amount'] : $amount);
|
||||||
|
watchdog('booking_debug', "Detected foreign card use (country !country), setting amount to !amount",
|
||||||
|
array('!country' => $card_country, '!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
|
||||||
|
@@ -7,11 +7,12 @@ jQuery(document).ready(function($) {
|
|||||||
locale: 'auto',
|
locale: 'auto',
|
||||||
token: function(token) {
|
token: function(token) {
|
||||||
try {
|
try {
|
||||||
//store the returned token into hidden form elements
|
//store relevant parts of the returned token into hidden form elements
|
||||||
$(':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="token_client_ip"]', $stripeForm).val(token.client_ip);
|
||||||
$(':input[name="card_brand"]', $stripeForm).val(token.card.brand);
|
$(':input[name="card_brand"]', $stripeForm).val(token.card.brand);
|
||||||
|
$(':input[name="card_country"]', $stripeForm).val(token.card.country);
|
||||||
$(':input[name="card_cvc_check"]', $stripeForm).val(token.card.cvc_check);
|
$(':input[name="card_cvc_check"]', $stripeForm).val(token.card.cvc_check);
|
||||||
$(':input[name="card_address_zip_check"]', $stripeForm).val(token.card.address_zip_check);
|
$(':input[name="card_address_zip_check"]', $stripeForm).val(token.card.address_zip_check);
|
||||||
$stripeForm.get(0).submit();
|
$stripeForm.get(0).submit();
|
||||||
|
Reference in New Issue
Block a user