定制 rapidwebltd/simplestripe 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rapidwebltd/simplestripe

Composer 安装命令:

composer require rapidwebltd/simplestripe

包简介

SimpleStripe makes it easier than ever to integrate basic Stripe-powered payments into a site. With only a small amount of code you can have a payment form ready to start charging customers.

README 文档

README

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.

{
  "require": {
       "rapidwebltd/simplestripe": "1.*"
   }
}

If your framework does not do so for you, remember to include the autoload files generated by composer, as follows.

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.

// 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.

// 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
// 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.

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2016-11-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固