Originally Posted by
tmccaff
I am going to test phase. As of now updated Api Version. Will test tonight
Ok it charges cutomer but when they come back have an issue:
I forget is there away to print array or debug this code?
Must provide source or customer:
Here is the old code:
PHP Code:
Stripe::setApiKey($secret_key);
$error = '';
// get the credit card details submitted by the form
$token = $_POST['StripeToken'];
//existing customer
if (zen_not_null($_POST['StripeCustomerID'])) {
if ($token == 'NONE') {
//charge the customer on existing card
try {
$charge = Stripe_Charge::create(array(
//"amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"customer" => $_POST['StripeCustomerID']
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
} //end use existing card
//start new card
//new card for the customer and he wants to save it (or we are not allowing the option do StripesaveCard==YES
elseif (zen_not_null($_POST['StripeSaveCard']) && ($_POST['StripeSaveCard'] == 'YES')) {
try {
//update the card for the customer
$cu = Stripe_Customer::retrieve($_POST['StripeCustomerID']);
$cu->source = $token;
$cu->save();
//charge the customer
$charge = Stripe_Charge::create(array(
//"amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"customer" => $_POST['StripeCustomerID']
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
} //end save card
else {
//a saved customer has entered new card details but does NOT want them saved. Currently (Nov 2012) Stripe does not allow you to remove a card object so you'll have to charge the card and not the customer
try {
// create the charge on Stripe's servers - this will charge the user's card no customer object
$charge = Stripe_Charge::create(array(
// "amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"card" => $token,
"description" => $order->customer['email_address']
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
}
} //end existing customer
//new customer wants to save card details
elseif (zen_not_null($_POST['StripeSaveCard']) && ($_POST['StripeSaveCard'] == 'YES')) {
//new customer create the object
try {
// create a Customer
$customer = Stripe_Customer::create(array(
"card" => $token,
"description" => $order->customer['email_address']
));
// charge the Customer instead of the card
$charge = Stripe_Charge::create(array(
// "amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"customer" => $customer->id
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
}
// not a customer token
else {
try {
// create the charge on Stripe's servers - this will charge the user's card no customer object
$charge = Stripe_Charge::create(array(
// "amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"card" => $token,
"description" => $order->customer['email_address']
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
} //end not a customer token
// die ( $charge);
return false;
}
I changed it to:
PHP Code:
\Stripe\Stripe::setApiKey($secret_key);
$error = '';
// get the credit card details submitted by the form
$token = $_POST['StripeToken'];
//existing customer
if (zen_not_null($_POST['StripeCustomerID'])) {
if ($token == 'NONE') {
//charge the customer on existing card
try {
$charge = \Stripe\Charge::create(array(
//"amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"customer" => $_POST['StripeCustomerID']
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
} //end use existing card
//start new card
//new card for the customer and he wants to save it (or we are not allowing the option do StripesaveCard==YES
elseif (zen_not_null($_POST['StripeSaveCard']) && ($_POST['StripeSaveCard'] == 'YES')) {
try {
//update the card for the customer
$customer = \Stripe\Customer::retrieve($_POST['StripeCustomerID']);
$customer->default_source = $card->id;
$customer->save();
//charge the customer
$charge = \Stripe\Charge::create(array(
//"amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"customer" => $_POST['StripeCustomerID']
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
} //end save card
else {
//a saved customer has entered new card details but does NOT want them saved. Currently (Nov 2012) Stripe does not allow you to remove a card object so you'll have to charge the card and not the customer
try {
// create the charge on Stripe's servers - this will charge the user's card no customer object
$charge = \Stripe\Charge::create(array(
// "amount" => ($order->info['total']) * 100, // amount in cents
//fimgirl fix for total
"amount" =>floor(($order->info['total']) * 100),
"currency" => MODULE_PAYMENT_STRIPEPAY_CURRENCY,
"card" => $token,
"description" => $order->customer['email_address']
));
}
catch (Exception $e) {
$error = $e->getMessage();
$messageStack->add_session('checkout_confirmation', $error . '<!-- [' . $this->code . '] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL', true, false));
}
}
} //end existing customer
It could be another area of code that is causing the problem not sure
Bookmarks