-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jordan Hall
committed
Nov 9, 2016
1 parent
3faf237
commit 10a8a6b
Showing
1 changed file
with
17 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
<?php | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
use \RapidWeb\SimpleStripe\Factories\SimpleStripeFactory; | ||
|
||
$simpleStripe = SimpleStripeFactory::create('PUBLISHABLE_KEY', 'SECRET_KEY', 'GBP'); // GBP = Great British Pounds | ||
// Setup SimpleStripe using Stripe API keys and currency | ||
$simpleStripe = \RapidWeb\SimpleStripe\Factories\SimpleStripeFactory::create('PUBLISHABLE_KEY', 'SECRET_KEY', 'GBP'); // GBP = Great British Pounds | ||
|
||
// If payment form has been submitted | ||
if (isset($_POST['stripeToken'])) { | ||
|
||
// Get the amount to charge (in the currency's lowest denomination) | ||
$amount = 500; // Five hundred pence = Five pounds (5 GBP) | ||
|
||
// Charge the customer | ||
$charge = $simpleStripe->charge($amount, $_POST['stripeToken']); | ||
|
||
if ($charge->succeeded) { | ||
|
||
// If charge succeeded, display success messsage | ||
echo "Success! <a href=\"Example.php\">Make another payment.</a>"; | ||
|
||
} elseif ($charge->problemType=='Card') { | ||
|
||
// If there was a problem with the card, display details of the problem | ||
echo $charge->problem; | ||
|
||
} else { | ||
if ($charge->problemType=='Card') { | ||
echo $charge->problem; | ||
} else { | ||
echo "Sorry, there was a problem processing your payment. <a href=\"Example.php\">Please try again.</a>"; | ||
} | ||
|
||
// Else, display a generic failure message | ||
echo "Sorry, there was a problem processing your payment. <a href=\"Example.php\">Please try again.</a>"; | ||
} | ||
|
||
die; | ||
} | ||
|
||
// Display a simple payment form | ||
echo $simpleStripe->paymentForm(); |