I'm attempting to use Stripe checkout in modx with a custom Formit hook. I am able to use Stripe's popup checkout and it sends the information to stripe. I then return to a must submit registration button that submits an entry form but first charge the card. This is my snippet.
require_once $modx->getOption('assets_path').'/lib/Stripe.php';
\Stripe::setApiKey("sk_test_Cxxxxxxxxxxxxxxxxxxxxxx");
$modx->log(xPDO::LOG_LEVEL_ERROR,'Set API.');
// get the credit card details submitted by the form
$amount = $_POST['total'];
$token = $_POST['stripeToken'];
$test = 100;
$modx->log(xPDO::LOG_LEVEL_ERROR, ($token));
$modx->log(xPDO::LOG_LEVEL_ERROR, ($amount * 100));
$modx->log(xPDO::LOG_LEVEL_ERROR, ($test));
try {
$modx->log(xPDO::LOG_LEVEL_ERROR,'try.');
$charge = \Stripe\Charge::create(array(
"amount" => ($amount * 100), // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "Vertical Runner")
);
$modx->log(xPDO::LOG_LEVEL_ERROR,'array.');
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
$modx->log(xPDO::LOG_LEVEL_ERROR,'Testing my custom hook.');
return true;</code>
The screen freezes on white after submit, and the form is never submitted. The error codes all show up till "Try"
I have tried the form without this snippet and it works.
I'm willing to charge the card as part of the pop-up checkout, but I'm unsure on how to do that.