loduis / stripe-migrate
将 Stripe 订阅迁移到新账户,此操作仅在克隆时执行
dev-master
2018-04-27 17:29 UTC
Requires
- loduis/stripe-finder: master
- stripe/stripe-php: ^6.6
This package is auto-updated.
Last update: 2024-09-19 12:55:13 UTC
README
注意:此源代码仅适用于一个订阅,对于客户
这是一个简单的迁移 Stripe 订阅的工具,运行此过程您需要
- 给 Stripe 团队写邮件以在新账户中创建客户副本
- 停止账户中的 webhooks
- 运行迁移
这会怎样?
- 当所有方法调用此操作时,会创建计划,或者您可以创建计划发票方法计划
- 在新账户中复制客户的当前订阅
- 将新账户的 trial_end 设置为旧账户的 current_period_end
- 标记订阅在周期结束时取消
使用说明
迁移一个客户的订阅
use Stripe\Tools\Migrate\Subscription as Migrate; require './vendor/autoload.php'; $migrate = new Migrate( 'stripe from account api key', 'stripe to account api key' //, true // force to live ); $callback = function ($err, $to, $from, $customer) { if ($err) { throw $err; } echo 'Customer: -> ', $customer, PHP_EOL; echo 'Old subscription: -> ', $from, PHP_EOL; echo 'New subscription: -> ', $to, PHP_EOL; // in this callback youn can update you database ids // if the callback return false the old subscription is not cancelled // you can no return any o return true for cancel subscription }; if ($migrate->run('stripe customer id', $callback) === false) { echo 'It was not possible to find an active subscription in', ' the old account or he already has a subscription in the new account'; }
迁移所有客户的订阅
use Stripe\Tools\Migrate; require './vendor/autoload.php'; $migrate = new Migrate( 'stripe from account api key', 'stripe to account api key' ); $migrate->run(function ($err, $to, $from, $customer) { if ($err) { throw $err; } echo 'Customer: -> ', $customer, PHP_EOL; echo 'Old subscription: -> ', $from, PHP_EOL; echo 'New subscription: -> ', $to, PHP_EOL; // you need store in database echo '---------------------------------', PHP_EOL; })