【问题标题】:Stripe Recurring Payments but every 3 or 6 months条纹定期付款,但每 3 或 6 个月
【发布时间】:2019-04-20 12:27:00
【问题描述】:

我是 Stripe PHP Laravel 的新手。对于不是 1 个月而是 3 个月或 6 个月的计费周期,是否可以在 Laravel Stripe 中进行定期付款?由于我不熟悉该术语,任何人都可以将我发送到正确的文档吗?我在 Stripe 中检查了周期,但我认为这不是我需要的。

【问题讨论】:

  • 不知道为什么所有的反对票都是针对一个非常有效的问题。我发现很难找到有关更改 Cashier/Stripe 间隔的信息 - 感谢您的提问,很高兴这里有答案!

标签: php laravel laravel-cashier


【解决方案1】:

在 belling-> 产品下的条带仪表板上创建新产品,例如 prod-1,将定价计划例如 plan-1(条带将为该计划生成 ID)添加到该产品(prod-1),同时添加定价计划在计费间隔下选择或自定义您想要的间隔。

现在让我们在 laravel 应用端工作。我会推荐使用 Laravel Cashier。

运行作曲家composer require laravel/cashier

更新您的 USER 迁移表:

 Schema::table('users', function ($table) {
    $table->string('stripe_id')->nullable()->collation('utf8mb4_bin');
    $table->string('card_brand')->nullable();
    $table->string('card_last_four', 4)->nullable();
    $table->timestamp('trial_ends_at')->nullable();
});

Schema::create('subscriptions', function ($table) {
    $table->increments('id');
    $table->unsignedInteger('user_id');
    $table->string('name');
    $table->string('stripe_id')->collation('utf8mb4_bin');
    $table->string('stripe_plan');
    $table->integer('quantity');
    $table->timestamp('trial_ends_at')->nullable();
    $table->timestamp('ends_at')->nullable();
    $table->timestamps();
});

更新您的用户模型:

use Laravel\Cashier\Billable;

class User extends Authenticatable
{
    use Billable;
}

在您的控制器中。 MyController.php:

use Cartalyst\Stripe\Laravel\Facades\Stripe;
use Cartalyst\Stripe\Exception\CardErrorException;
use Session;
use Auth;

public function store(Request $request)
{

    $token = $_POST['stripeToken'];
    $user = Auth::user();

    try {

        $user->newSubscription('prod-1', 'ID of plan-1')->create($token);

        Session::flash('success', 'You are now a premium member');
        return redirect()->back();

    } catch (CardErrorException $e) {
        return back()->withErrors('Error!'.  $e->getMessage());
    }


}

在你看来:

<form action="{{ route('subscribe')}}" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_0000000000000000000" // Your api key
    data-image="/images/marketplace.png" // You can change this image to your image
    data-name="My App Name"
    data-description="Subscription for 1 weekly box"
    data-amount="2000" //the price is in cents 2000 = 20.00
    data-label="Sign Me Up!">
  </script>
</form>

创建路线:

Route::POST('subscription', 'MyController@store')->name('susbcribe');

让我知道它是否有效。

【讨论】:

  • 谢谢。我真的很想知道为什么这个问题被否决了。事实证明,此设置在 Stripe 中可用。非常感谢!
  • @James Arnold,这是因为您没有在问题中发布任何代码。这里的规则是,您必须在遇到困难的地方共享代码,以便人们可以查看并帮助您解决问题,而不是从头开始。
猜你喜欢
  • 2022-01-05
  • 2017-02-13
  • 1970-01-01
  • 2017-05-12
  • 2016-01-25
  • 2018-11-17
  • 2013-04-20
  • 2015-12-15
  • 2013-11-08
相关资源
最近更新 更多