aamroni/stripe

Stripe API 支付在 Laravel 中

1.0.0 2024-04-01 18:21 UTC

This package is auto-updated.

Last update: 2024-10-01 00:08:56 UTC


README

Laravel Logo

安装

composer require aamroni/stripe

配置示例

收集您的公共和秘密密钥,并在 config/payment.php 中进行必要配置

'stripe' => [
    'public'        => env('STRIPE_PUBLIC_KEY'),
    'secret'        => env('STRIPE_SECRET_KEY'),
    'redirect'      => [
        'success'   => 'https://:8000/stripe/success',
        'cancel'    => 'https://:8000/stripe/cancel'
    ],
    'currency'      => 'USD'
]

结账示例

<?php

use Aamroni\Stripe\Entities\CustomerEntity;
use Aamroni\Stripe\Entities\PurchaseEntity;
use Aamroni\Stripe\Facades\Stripe;
use Aamroni\Stripe\StripePaymentManager;

// @step01: Create a customer information
$customer = CustomerEntity::instance(
    name: 'James Wilson',
    email: 'james.wilson@example.com',
    mobile: '+1 562-506-8893',
    street: '2812 Locust Court',
    city: 'Irvine',
    postal: '92614',
    state: 'California',
    country: 'US'
);

// @step02: Create a purchase information
$purchase = PurchaseEntity::instance(
    title: 'FoldSack No. 1 Backpack, Fits 15 Laptops',
    quantity: 1,
    regular: 109.95,
    offered: 99,
    currency: 'USD'
);

// @step03: Process the Stripe checkout
$stripe = Stripe::checkout($customer, $purchase);
// or
$stripe = StripePaymentManager::instance()->checkout($customer, $purchase);

dd($stripe);

客户示例

<?php

use Aamroni\Stripe\Contracts\CustomerContract;

$instance = CustomerContract::instance();
$response = $instance->create(CustomerEntity: $customer); // Create a customer information
$response = $instance->delete(); // Delete a customer information
$response = $instance->record(); // Fetch all customer information
$response = $instance->record(id: $id); // Fetch a specific customer information

dd($response);

购买示例

<?php

use Aamroni\Stripe\Contracts\PurchaseContract;

$instance = PurchaseContract::instance();
$response = $instance->create(PurchaseEntity: $purchase); // Create a purchase information
$response = $instance->record(); // Fetch all purchase information
$response = $instance->record(id: $id); // Fetch a specific purchase information

dd($response);