Skip to content

Commit

Permalink
Improvements to example file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Hall committed Nov 9, 2016
1 parent 3faf237 commit 10a8a6b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Example.php
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();

0 comments on commit 10a8a6b

Please sign in to comment.