Created
December 14, 2021 16:17
-
-
Save leroyrosales/822c0b7af41ee3dd51fa24e4c569a5d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require '../vendor/autoload.php'; | |
// Is this actually an AJAX request | |
if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && ! empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) { | |
exit; | |
} | |
// Let's us use WP functions | |
require_once $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'; | |
// Get secret key from site options | |
$secret_key = get_field( 'secret_key', 'option' ); | |
\Stripe\Stripe::setApiKey( $secret_key ); | |
// header( 'Content-Type: application/json' ); | |
// Sanitize POST Array | |
$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING); | |
$fname = isset($_POST["fname"]) ? sanitize_text_field($_POST["fname"]) : ''; | |
$lname = isset($_POST["lname"]) ? sanitize_text_field($_POST["lname"]) : ''; | |
$email = isset($_POST["email"]) ? sanitize_text_field($_POST["email"]) : ''; | |
// Calculate promo amount | |
$promo_exists = false; | |
$amount = 49900; //$499.00 | |
// Get promo from form | |
$promo_code = isset($_POST["promo"]) ? sanitize_text_field($_POST["promo"]) : ''; | |
$description = "Artificial Intelligence Solutions: An Introductory View from a Human-Machine Perspective"; | |
$site_domain = get_site_url(); | |
// Create Customer In Stripe | |
$customer = \Stripe\Customer::create(array( | |
"email" => $email, | |
"name" => $fname . ' ' . $lname, | |
"description" => $description, | |
"metadata" => [ | |
"first_name" => $fname, | |
"last_name" => $lname, | |
], | |
)); | |
$checkout_session = \Stripe\Checkout\Session::create(array( | |
'line_items' => array( | |
array( | |
'amount' => $amount, | |
'quantity' => 1, | |
'currency' => 'usd', | |
'name' => $description, | |
), | |
), | |
'mode' => 'payment', | |
"metadata" => [ | |
"first_name" => $fname, | |
"last_name" => $lname, | |
], | |
'allow_promotion_codes' => true, | |
'success_url' => $site_domain . '/thank-you', | |
'cancel_url' => $site_domain . '/register', | |
)); | |
header( 'HTTP/1.1 303 See Other' ); | |
header( 'Location: ' . $checkout_session->url ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment