Prevent empty registration, send Stripe email receipts

master
Skylar Ittner 5 years ago
parent 4e1db1575a
commit 43095c6241

@ -25,6 +25,8 @@ $database->action(function($database) {
$dueusd = 0.0; $dueusd = 0.0;
$emails = [];
try { try {
$people = $_POST['people']; $people = $_POST['people'];
@ -40,6 +42,10 @@ $database->action(function($database) {
"sex" => ["M", "F"] "sex" => ["M", "F"]
]; ];
if (count($people['ids']) == 0) {
errorBack("You need to register at least one person.");
}
foreach ($people['ids'] as $pid) { foreach ($people['ids'] as $pid) {
// Clear these out // Clear these out
$camperid = null; $camperid = null;
@ -173,6 +179,10 @@ $database->action(function($database) {
"shirt" => $people["shirt"][$pid], "shirt" => $people["shirt"][$pid],
"sex" => $people["sex"][$pid] "sex" => $people["sex"][$pid]
]); ]);
if (!empty($people["email"][$pid])) {
$emails[] = $people["email"][$pid];
}
} }
} catch (Exception $ex) { } catch (Exception $ex) {
errorBack($ex->getMessage()); errorBack($ex->getMessage());
@ -203,29 +213,34 @@ $database->action(function($database) {
try { try {
\Stripe\Stripe::setApiKey($SETTINGS["stripe"]["seckey"]); \Stripe\Stripe::setApiKey($SETTINGS["stripe"]["seckey"]);
$charge = \Stripe\Charge::create([ $chargedata = [
'amount' => $duecard * 100.0, 'amount' => $duecard * 100.0,
'currency' => 'usd', 'currency' => 'usd',
'description' => 'Day Camp', 'description' => 'Day Camp ' . date('Y'),
'source' => $_POST['stripeToken'], 'source' => $_POST['stripeToken']
'statement_descriptor' => 'PPD Day Camp', ];
]);
if (count($emails) > 0) {
$chargedata['receipt_email'] = $emails[0];
}
$charge = \Stripe\Charge::create($chargedata);
} catch (\Stripe\Error\Card $e) { } catch (\Stripe\Error\Card $e) {
$body = $e->getJsonBody(); $body = $e->getJsonBody();
$err = $body['error']; $err = $body['error'];
errorBack("We couldn't process your card because it was declined. Your card issuer or bank sent us this message: " . $err["message"] . " That's all we know."); errorBack("We couldn't process your card because it was declined. Your card issuer or bank sent us this message: " . $err["message"] . " That's all we know.");
} catch (\Stripe\Error\RateLimit $e) { } catch (\Stripe\Error\RateLimit $e) {
errorBack("We couldn't process your card because things are happening too fast. Please try again in a minute. (Error code: STRIPE_RATELIMIT)"); errorBack("We couldn't process your card because things are happening too fast. Please try again in a minute. Your card was not charged. (Error code: STRIPE_RATELIMIT)");
} catch (\Stripe\Error\InvalidRequest $e) { } catch (\Stripe\Error\InvalidRequest $e) {
errorBack("We couldn't process your card because of a technical issue. Please try again later. (Error code: STRIPE_INVREQ)"); errorBack("We couldn't process your card because of a technical issue. Please try again later. Your card was not charged. (Error code: STRIPE_INVREQ)");
} catch (\Stripe\Error\Authentication $e) { } catch (\Stripe\Error\Authentication $e) {
errorBack("We can't connect to the card processor. Please try again later. (Error code: STRIPE_AUTH)"); errorBack("We can't connect to the card processor. Please try again later. Your card was not charged. (Error code: STRIPE_AUTH)");
} catch (\Stripe\Error\ApiConnection $e) { } catch (\Stripe\Error\ApiConnection $e) {
errorBack("We can't connect to the card processor. Please try again later. (Error code: STRIPE_NOAPI)"); errorBack("We can't connect to the card processor. Please try again later. Your card was not charged. (Error code: STRIPE_NOAPI)");
} catch (\Stripe\Error\Base $e) { } catch (\Stripe\Error\Base $e) {
errorBack("An unknown payment error occurred. Please try again later."); errorBack("An unknown payment error occurred. Please try again later. Your card was not charged.");
} catch (Exception $e) { } catch (Exception $e) {
errorBack("An unknown error occurred. Please try again later."); errorBack("An unknown error occurred. Please try again later. Your card was not charged.");
} }
} }

Loading…
Cancel
Save