承接 programster/stripe-wrapper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

programster/stripe-wrapper

最新稳定版本:0.1.0

Composer 安装命令:

composer require programster/stripe-wrapper

包简介

A wrapper around the stipe/stripe-php SDK in order to make life easier.

关键字:

README 文档

README

A wrapper around the stripe/stripe-php package to make it easier to use Stripe without having to read the documentation. You just need to fill in the constructors and their parameters.

Example Usage

Below are some examples for creating a checkout session.

Single Payment Example

This is an example of the most common use-case, of just charging the customer once for a set of items they wish to purchase.

<?php

use Programster\Stripe\Collections\SinglePaymentLineItemsCollection;
use Programster\Stripe\Collections\SubscriptionLineItemCollection;
use Programster\Stripe\Enums\Currency;
use Programster\Stripe\Enums\RecurringInterval;
use Programster\Stripe\Models\AdjustableQuantityConfig;
use Programster\Stripe\Models\FlowConfig;
use Programster\Stripe\Models\PriceDataForSinglePayment;
use Programster\Stripe\Models\RecurringConfig;
use Programster\Stripe\Models\SinglePaymentLineItem;
use Programster\Stripe\Models\SubscriptionLineItem;
use Programster\Stripe\Models\PriceDataForSubscription;
use Programster\Stripe\Models\ProductData;
use Programster\Stripe\StripeClient;

require_once(__DIR__ . '/../vendor/autoload.php');

# define your private Stripe API Key.
define('STRIPE_SECRET_KEY', 'sk_test_...');

$client = new StripeClient(STRIPE_SECRET_KEY);
$flowConfig = FlowConfig::createHosted(successUrl: "http://localhost/success");

$shirt = new PriceDataForSinglePayment(
    currency: Currency::GBP,
    unitAmount: 2000,
    productDataOrId: new ProductData(
        name: "T-shirt",
        description: "A designer t-shirt."
    )
);

$shorts = new PriceDataForSinglePayment(
    currency: Currency::GBP,
    unitAmount: 1500,
    productDataOrId: new ProductData(
        name: "Shorts"
    )
);

$items = new SinglePaymentLineItemsCollection(
    new SinglePaymentLineItem(
        quantity: 1,
        priceDataOrPriceId: $shirt,
        adjustableQuantityConfig: new AdjustableQuantityConfig(1, 100)
    ),
    new SinglePaymentLineItem(
        quantity: 1,
        priceDataOrPriceId: $shorts,
        adjustableQuantityConfig: new AdjustableQuantityConfig(1, 100)
    )
);

$checkoutSession = $client->createCheckoutSessionForSinglePayment(
    flowConfig: $flowConfig,
    items: $items,
);

# Redirect the user to the stripe payment page.
http_response_code(303);
header('Location: ' . $checkoutSession->url);

Subscription Example

The example below will create a subscription checkout session, charging the user once a month. This is could be for if you were setting up your own Dollar Shave club, or Netflix subscription.

<?php

use Programster\Stripe\Collections\SinglePaymentLineItemsCollection;
use Programster\Stripe\Collections\SubscriptionLineItemCollection;
use Programster\Stripe\Enums\Currency;
use Programster\Stripe\Enums\RecurringInterval;
use Programster\Stripe\Models\AdjustableQuantityConfig;
use Programster\Stripe\Models\FlowConfig;
use Programster\Stripe\Models\PriceDataForSinglePayment;
use Programster\Stripe\Models\RecurringConfig;
use Programster\Stripe\Models\SinglePaymentLineItem;
use Programster\Stripe\Models\SubscriptionLineItem;
use Programster\Stripe\Models\PriceDataForSubscription;
use Programster\Stripe\Models\ProductData;
use Programster\Stripe\StripeClient;

require_once(__DIR__ . '/../vendor/autoload.php');

# define your private Stripe API Key.
define('STRIPE_SECRET_KEY', 'sk_test_...');

$client = new StripeClient(STRIPE_SECRET_KEY);
$flowConfig = FlowConfig::createHosted(successUrl: "http://localhost/success");
$recurringConfig = new RecurringConfig(RecurringInterval::MONTH, 1);

$shirt = new PriceDataForSubscription(
    currency: Currency::GBP,
    unitAmount: 2000,
    productDataOrId: new ProductData(
        name: "T-shirt",
        description: "A designer t-shirt."
    ),
    recurring: $recurringConfig,
);

$shorts = new PriceDataForSubscription(
    currency: Currency::GBP,
    unitAmount: 1500,
    productDataOrId: new ProductData(
        name: "Shorts"
    ),
    recurring: $recurringConfig,
);

$items = new SubscriptionLineItemCollection(
    new SubscriptionLineItem(
        quantity: 1,
        priceDataOrPriceId: $shirt,
        adjustableQuantityConfig: new AdjustableQuantityConfig(1, 100)
    ),
    new SubscriptionLineItem(
        quantity: 1,
        priceDataOrPriceId: $shorts,
        adjustableQuantityConfig: new AdjustableQuantityConfig(1, 100)
    )
);

$checkoutSession = $client->createCheckoutSessionForSubscription(
    flowConfig: $flowConfig,
    items: $items,
);

# Redirect the user to the stripe payment page.
http_response_code(303);
header('Location: ' . $checkoutSession->url);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-22