php 如何在laravel中为stripe中的不同帐户配置转账

9gm1akwq  于 2023-09-29  发布在  PHP
关注(0)|答案(1)|浏览(110)

我在一个平台上工作,我想自己收取佣金。这是我现在的代码:

  1. class StripePayment
  2. {
  3. private ?Authenticatable $user;
  4. public function __construct(
  5. private readonly Stripe $stripe,
  6. private StripeClient $stripeClient,
  7. private readonly Charge $charge,
  8. private readonly Transfer $transfer
  9. )
  10. {
  11. $this->user = auth()->user();
  12. $this->stripe::setApiKey(env('STRIPE_SECRET'));
  13. $this->stripeClient = new StripeClient(env('STRIPE_SECRET'));
  14. }
  15. public function charge(array $prices, string $paymentToken)
  16. {
  17. $stripeResponse = $this->createOrUpdateCustomer($paymentToken);
  18. $payment = $this->charge::create([
  19. 'amount' => $prices['clubPrice'] * 100,
  20. 'currency' => 'eur',
  21. 'customer' => $stripeResponse->id,
  22. 'description' => __('Reservation created')
  23. ]);
  24. $clubTransfer = $this->transfer::create([
  25. 'amount' => $prices['clubPrice'] * 100,
  26. 'currency' => 'eur',
  27. 'destination' => 'default_for_currency',
  28. 'transfer_group' => $payment->id,
  29. ]);
  30. $yourTransfer = $this->transfer::create([
  31. 'amount' => $prices['ourPrice'] * 100,
  32. 'currency' => 'eur',
  33. 'destination' => 'default_for_currency',
  34. 'transfer_group' => $payment->id,
  35. ]);
  36. dd($clubTransfer);
  37. }
  38. public function createOrUpdateCustomer(string $token)
  39. {
  40. if ($this->user->stripe_id) {
  41. $stripeResponse = $this->stripeClient->customers->update(
  42. $this->user->stripe_id,
  43. [
  44. 'name' => $this->user->name,
  45. 'email' => $this->user->email,
  46. 'source' => $token,
  47. ]
  48. );
  49. } else {
  50. $stripeResponse = $this->stripeClient->customers->create([
  51. 'name' => $this->user->name,
  52. 'email' => $this->user->email,
  53. 'source' => $token,
  54. ]);
  55. $this->user->stripe_id = $stripeResponse->id;
  56. $this->user->save();
  57. }
  58. return $stripeResponse;
  59. }
  60. }

在$prices数组中,我有:

  1. array:2 [ // app/Services/StripePayment.php:29
  2. "clubPrice" => 9.2
  3. "ourPrice" => 0.8
  4. ]

我想做的是将“ourPrice”记入我的银行账户,将“clubPrice”记入另一个银行账户。我如何才能做到这一点?目前处于开发模式
我试过了,但是没有结果

  1. $stripeResponse = $this->createOrUpdateCustomer($paymentToken);
  2. $payment = $this->charge::create([
  3. 'amount' => $prices['clubPrice'] * 100,
  4. 'currency' => 'eur',
  5. 'customer' => $stripeResponse->id,
  6. 'description' => __('Reservation created')
  7. ]);
  8. $clubTransfer = \Stripe\Transfer::create([
  9. 'amount' => $prices['clubPrice'] * 100,
  10. 'currency' => 'eur',
  11. 'destination' => 'acct_1234567890',
  12. 'transfer_group' => $payment->id,
  13. ]);
  14. // Realizar la transferencia a tu cuenta
  15. $yourTransfer = \Stripe\Transfer::create([
  16. 'amount' => $prices['ourPrice'] * 100,
  17. 'currency' => 'eur',
  18. 'destination' => 'acct_0987654321',
  19. 'transfer_group' => $payment->id,
  20. ]);
oknwwptz

oknwwptz1#

这听起来像是你试图使用Stripe所谓的“Separate Charges and Transfers”,但你使用的是Charges API,它是遗留的,并不容易支持所有相同的功能。我建议升级到支付意向和使用条纹的新产品
如果您必须使用传统的Charges API,则可能会在成功充值后尝试转移超过您可用的金额,因为看起来您可能会为prices['clubPrice'] * 100创建一个费用,然后随后向2个不同的Connect帐户进行x2次后续转移。
你有什么错误吗?如果是,它们是什么?当你说“我试过了,但没有结果”,你是什么意思?

相关问题