Stripe Checkout Pages Using PHP | Lon Hosford www.lonhosford.com Charging the Card START SNIPPET #1: // General website data $company_name = "Acme Widgets Inc."; // Order Data $description = "Widgets"; $quantity = 12; $amount = 20.00; SNIPPET #2:

Item:

Quantity:

SNIPPET #3: data-key="" data-amount="" data-name="" data-description="" SNIPPET #4: // View data $url_self = $_SERVER['PHP_SELF']; SNIPPET #5:
SNIPPET #6: // Checkout has occured. Process payment. if (isset($_POST['stripeToken'])){ include 'checkout_charge_card.inc.php'; } SNIPPET #7: // Data to return $return_data = array(); // Save $_POST for debugging $return_data['post'] = $_POST; // Success or failure $return_data["success"] = false; SNIPPET #8:

*** TESTING ***

Testing Reset

$return_data: ' , print_r($return_data,true) , ''; } ?>
CHECK POINT #1 SNIPPET #9: // Authenticate to the Stripe API \Stripe\Stripe::setApiKey($st_test_secret_key); SNIPPET #10: // Create the charge on Stripe's servers - this will charge the user's card try{ // Create a Stripe\Charge OOP object $charge = \Stripe\Charge::create(array( "amount" => $amount * 100, // Convert to cents "currency" => "usd", "source" => $_POST['stripeToken'], "receipt_email" => $_POST['stripeEmail'], "description" => $quantity . ' ' . $description) ); $return_data["success"] = true; //Invalid request errors arise when your request has invalid parameters. }catch(\Stripe\Error\InvalidRequest $e){ $return_data['error']['httpStatus'] = $e->getHttpStatus() ; } CHECK POINT #2: SNIPPET #11: $return_data["charge"]["id"] = $charge->id; $return_data["charge"]["status"] = $charge->status; CHECK POINT #3: SNIPPET #12: $body = $e->getJsonBody(); $error_info = $body['error']; $return_data['error']['type'] = $error_info['type']; if(isset($error_info['message'])){ $return_data['error']['message'] = $error_info['message']; } CHECK POINT #4: SNIPPET #13: $statement_descriptor = "ACME 12 WIDGETS"; SNIPPET #14: "statement_descriptor" => $statement_descriptor, COMPLETED