Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rapidwebltd/simplestripe
💳 SimpleStripe is a really easy way to integrate basic Stripe-powered payments.
https://github.com/rapidwebltd/simplestripe
payment-form php-library stripe stripe-powered-payments
Last synced: about 1 month ago
JSON representation
💳 SimpleStripe is a really easy way to integrate basic Stripe-powered payments.
- Host: GitHub
- URL: https://github.com/rapidwebltd/simplestripe
- Owner: rapidwebltd
- License: lgpl-3.0
- Created: 2016-11-09T09:50:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-30T19:37:42.000Z (almost 7 years ago)
- Last Synced: 2023-08-12T05:34:31.585Z (over 1 year ago)
- Topics: payment-form, php-library, stripe, stripe-powered-payments
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleStripe
This super simple Stripe integration package allow you to integrate
a Stripe powered payment form and charge your customers with only
a tiny amount of code.## Installation & Dependencies
This package and its dependencies can be installed using composer.
Just add the package to your composer.json file as follows and run
`composer update`.```json
{
"require": {
"rapidwebltd/simplestripe": "1.*"
}
}
```If your framework does not do so for you, remember to include the
autoload files generated by composer, as follows.```php
require_once 'vendor/autoload.php';
```## Setup
To use SimpleStripe, you must first instantiate the
`SimpleStripe` object. To do this, all you need is the Stripe API
keys and the currency you wish to take payments in.```php
// Setup SimpleStripe using Stripe API keys and currency
$simpleStripe = \RapidWeb\SimpleStripe\Factories\SimpleStripeFactory::create('PUBLISHABLE_KEY', 'SECRET_KEY', 'GBP');
```You can find your Stripe API keys within your
https://dashboard.stripe.com/account/apikeys. You will need both
the secret key and the publishable key.The currency must be presented in ISO 4217 format, such as GBP, USD, EUR.
## Displaying payment form
The following code will display a simple payment form, suitable for taking
payment with all common debit and credit cards.```php
// Display a simple payment form
echo $simpleStripe->paymentForm();
```This code will also include all the necessary JavaScript code to handle
client-side communication with Stripe and display of validation errors.
The form will post back to the same URL it is displayed upon.## Charging the customer
Charging customers is simple. The following code is an example
of how you can:1. Handle the payment form post back
2. Attempt to charge the customer
3. Handle success or failure```php
// 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, or perhaps redirect the user to a success page
echo "Success!";
exit;} elseif ($charge->problemType=='Card') {
// If there was a problem with the card, display details of the problem
echo $charge->problem;} else {
// Else, display a generic failure message
echo "Sorry, there was a problem processing your payment.";
}
}
```You should include code similar to this towards the top of the page
containing your payment form.## Example
For a complete implementation of SimpleStripe, see `src/Example.php`.
## License
This library is licensed under the Lesser General Public License
version 3.