我在一个平台上工作,我想自己收取佣金。这是我现在的代码:
class StripePayment
{
private ?Authenticatable $user;
public function __construct(
private readonly Stripe $stripe,
private StripeClient $stripeClient,
private readonly Charge $charge,
private readonly Transfer $transfer
)
{
$this->user = auth()->user();
$this->stripe::setApiKey(env('STRIPE_SECRET'));
$this->stripeClient = new StripeClient(env('STRIPE_SECRET'));
}
public function charge(array $prices, string $paymentToken)
{
$stripeResponse = $this->createOrUpdateCustomer($paymentToken);
$payment = $this->charge::create([
'amount' => $prices['clubPrice'] * 100,
'currency' => 'eur',
'customer' => $stripeResponse->id,
'description' => __('Reservation created')
]);
$clubTransfer = $this->transfer::create([
'amount' => $prices['clubPrice'] * 100,
'currency' => 'eur',
'destination' => 'default_for_currency',
'transfer_group' => $payment->id,
]);
$yourTransfer = $this->transfer::create([
'amount' => $prices['ourPrice'] * 100,
'currency' => 'eur',
'destination' => 'default_for_currency',
'transfer_group' => $payment->id,
]);
dd($clubTransfer);
}
public function createOrUpdateCustomer(string $token)
{
if ($this->user->stripe_id) {
$stripeResponse = $this->stripeClient->customers->update(
$this->user->stripe_id,
[
'name' => $this->user->name,
'email' => $this->user->email,
'source' => $token,
]
);
} else {
$stripeResponse = $this->stripeClient->customers->create([
'name' => $this->user->name,
'email' => $this->user->email,
'source' => $token,
]);
$this->user->stripe_id = $stripeResponse->id;
$this->user->save();
}
return $stripeResponse;
}
}
在$prices数组中,我有:
array:2 [ // app/Services/StripePayment.php:29
"clubPrice" => 9.2
"ourPrice" => 0.8
]
我想做的是将“ourPrice”记入我的银行账户,将“clubPrice”记入另一个银行账户。我如何才能做到这一点?目前处于开发模式
我试过了,但是没有结果
$stripeResponse = $this->createOrUpdateCustomer($paymentToken);
$payment = $this->charge::create([
'amount' => $prices['clubPrice'] * 100,
'currency' => 'eur',
'customer' => $stripeResponse->id,
'description' => __('Reservation created')
]);
$clubTransfer = \Stripe\Transfer::create([
'amount' => $prices['clubPrice'] * 100,
'currency' => 'eur',
'destination' => 'acct_1234567890',
'transfer_group' => $payment->id,
]);
// Realizar la transferencia a tu cuenta
$yourTransfer = \Stripe\Transfer::create([
'amount' => $prices['ourPrice'] * 100,
'currency' => 'eur',
'destination' => 'acct_0987654321',
'transfer_group' => $payment->id,
]);
1条答案
按热度按时间oknwwptz1#
这听起来像是你试图使用Stripe所谓的“Separate Charges and Transfers”,但你使用的是Charges API,它是遗留的,并不容易支持所有相同的功能。我建议升级到支付意向和使用条纹的新产品
如果您必须使用传统的Charges API,则可能会在成功充值后尝试转移超过您可用的金额,因为看起来您可能会为
prices['clubPrice'] * 100
创建一个费用,然后随后向2个不同的Connect帐户进行x2次后续转移。你有什么错误吗?如果是,它们是什么?当你说“我试过了,但没有结果”,你是什么意思?