progress stripe implementation

This commit is contained in:
Nathan Coad
2016-07-21 15:43:51 +10:00
parent 62060f075a
commit 6172866bf4
3 changed files with 15 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ function booking_balance_page() {
//populate tokens and paypal form
$tokens = booking_define_personspecific_tokens($node);
// @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['stripe-total-form'] = _booking_stripe_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");

View File

@@ -246,6 +246,7 @@ function booking_menu() {
'type' => MENU_NORMAL_ITEM,
);
// @todo remove this after testing
/*
$items['stripetest'] = array(
'title' => $bookingTitle . ' Stripe Test',
'page callback' => 'drupal_get_form',
@@ -253,6 +254,7 @@ function booking_menu() {
'access arguments' => array('access booking form'),
'type' => MENU_NORMAL_ITEM,
);
*/
$items['bookingfinal'] = array(
'title' => $bookingTitle . ' Registration Completed',
'page callback' => 'booking_payment_completed_page',

View File

@@ -78,6 +78,7 @@ function booking_stripe_form($node, &$form_state, $person, $invoiceid, $amount_o
'amount' => $amount_owing,
'last_name' => $person->booking_lastname,
'first_name' => $person->booking_firstname,
'uuid' => $person->booking_tempid,
'token_id' => '',
'token_email' => ''
);
@@ -260,9 +261,12 @@ function booking_stripe_validate_form_payment($form, &$form_state) {
\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'] : '');
$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'] : '');
watchdog('booking_debug', "<pre>Stripe payment form :\n@info</pre>", array('@info' => print_r( $form_state, true)));
// Create the charge on Stripe's servers - this will charge the user's card
@@ -271,19 +275,24 @@ function booking_stripe_validate_form_payment($form, &$form_state) {
"amount" => $amount * 100,
"currency" => "aud",
"card" => $token,
"statement_descriptor" => substr($event->booking_eventname, 0, 21), //this field is limited to 22 characters
"expand" => array('balance_transaction'),
"description" => $form_state['input']['description'],
"receipt_email" => $form_state['input']['email'],
"metadata" => array(
"invoice" => $invoice,
"nid" => $nid,
),
));
watchdog('booking_debug', "<pre>Stripe payment charge results:\n@info</pre>", array('@info' => print_r( $charge, true)));
if ($charge && $charge->paid) {
watchdog('booking', 'Charge created successfully');
$form_state['stripeform_charge'] = $charge;
watchdog('booking_debug', "<pre>Stripe payment charge results:\n@info</pre>", array('@info' => print_r( $charge, true)));
drupal_goto('bookingfinal');
// @todo call _booking_process_stripe_payment to store payment
drupal_goto('bookingfinal/' . $tempid);
}
else {
watchdog('booking', 'Charge was not created successfully');
drupal_set_message('Card does not seem to have been charged successfully. Please try again', 'error');
}
}