Prevent empty registration, send Stripe email receipts
This commit is contained in:
parent
4e1db1575a
commit
43095c6241
@ -25,6 +25,8 @@ $database->action(function($database) {
|
||||
|
||||
$dueusd = 0.0;
|
||||
|
||||
$emails = [];
|
||||
|
||||
try {
|
||||
|
||||
$people = $_POST['people'];
|
||||
@ -40,6 +42,10 @@ $database->action(function($database) {
|
||||
"sex" => ["M", "F"]
|
||||
];
|
||||
|
||||
if (count($people['ids']) == 0) {
|
||||
errorBack("You need to register at least one person.");
|
||||
}
|
||||
|
||||
foreach ($people['ids'] as $pid) {
|
||||
// Clear these out
|
||||
$camperid = null;
|
||||
@ -173,6 +179,10 @@ $database->action(function($database) {
|
||||
"shirt" => $people["shirt"][$pid],
|
||||
"sex" => $people["sex"][$pid]
|
||||
]);
|
||||
|
||||
if (!empty($people["email"][$pid])) {
|
||||
$emails[] = $people["email"][$pid];
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
errorBack($ex->getMessage());
|
||||
@ -203,29 +213,34 @@ $database->action(function($database) {
|
||||
try {
|
||||
\Stripe\Stripe::setApiKey($SETTINGS["stripe"]["seckey"]);
|
||||
|
||||
$charge = \Stripe\Charge::create([
|
||||
'amount' => $duecard * 100.0,
|
||||
'currency' => 'usd',
|
||||
'description' => 'Day Camp',
|
||||
'source' => $_POST['stripeToken'],
|
||||
'statement_descriptor' => 'PPD Day Camp',
|
||||
]);
|
||||
$chargedata = [
|
||||
'amount' => $duecard * 100.0,
|
||||
'currency' => 'usd',
|
||||
'description' => 'Day Camp ' . date('Y'),
|
||||
'source' => $_POST['stripeToken']
|
||||
];
|
||||
|
||||
if (count($emails) > 0) {
|
||||
$chargedata['receipt_email'] = $emails[0];
|
||||
}
|
||||
|
||||
$charge = \Stripe\Charge::create($chargedata);
|
||||
} catch (\Stripe\Error\Card $e) {
|
||||
$body = $e->getJsonBody();
|
||||
$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.");
|
||||
} 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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
errorBack("An unknown error occurred. Please try again later.");
|
||||
errorBack("An unknown error occurred. Please try again later. Your card was not charged.");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user