Symfony2-条带集成示例

下载 Stripe API 库并将其放在供应商文件夹中

来源:[ https://github.com/stripe/stripe-php] [1 ]

在控制器中包含库

use Stripe\BalanceTransaction;
use Stripe\Charge;
use Stripe\Stripe;
require_once('../vendor/stripe/init.php');

设置条带键

 \Stripe\Stripe::setApiKey('stripe_secret_key');

调用交易的收费功能

$card = array(
    'number' =>'cardccn',
    'cvc' =>'cardcvc',
    'exp_month' => 'expMonth',
    'exp_year' => 'expYear',
    );
    
$charge = Charge::create(
    array(
        'amount' => ('amount') * 100, // Amount will store in cent in Stripe Account
        'currency' => 'usd',
        'card' => $card,
        'description' => '$data['description',
        'receipt_email'=>'receipt_email'
        )
    );

得到充电的细节

 $data = Charge::retrieve('ch_%');