我的目标是将我的 Strype 资金转移到别人的银行账户。我正在尝试以下方法。
// generate test bank account token
public function generateBankAccountToken()
{
Stripe::setApiKey(config('stripe.sk'));
try {
$token = Token::create([
'bank_account' => [
'country' => 'US',
'currency' => 'usd',
'account_holder_name' => 'Test User',
'account_holder_type' => 'individual',
'routing_number' => '110000000', // Test routing number
'account_number' => '000999999991', // Test account number
],
]);
return response()->json(['token' => $token]);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
// to redirect amount from stripe to bank account
public function initiateTransfer(Request $request)
{
$input = $request->validate([
'account' => ['required'],
'amount' => ['required', new CheckBalance],
]);
// set the stripe API token
Stripe::setApiKey(config('stripe.sk'));
try {
// Create a transfer to the recipient's bank account
$transfer = Transfer::create([
'amount' => 100,
'currency' => 'usd', // Currency code
'destination' => 'abtok_1PVXsvAzd6Qck0TGa8chJlfd', // Replace with recipient's Stripe account ID
'description' => 'Refund from balance', // Optional description
]);
// Redirect the user to the Stripe transfer page
return redirect()->away($transfer->destination_payment_url);
} catch (Exception $e) {
// Handle transfer failure
dd($e);
return back()->withError('Transfer could not be initiated: ' . $e->getMessage());
}
}
在路线文件中:
Route::put('/recharge/initiate-Transfer', 'initiateTransfer')->name('strype.initiate.transfer');
Route::get('test/bank-account', 'generateBankAccountToken')->name('strype.test.bank');
调用
strype.test.bank
路线后,我得到了令牌:btok_1PVXsvAzd6Qck0TGa8chJlfd
。
但是,在
initiateTransfer
函数上应用令牌后,我收到以下错误。
Stripe\Exception\InvalidRequestException {#1605 ▼ // app\Http\Controllers\PaymentController\StripeController.php:156
#message: "No such destination: 'acct_1MQccXIQ2pUmxoSJ'"
#code: 0
.........................................
以下是如何使用 Stripe Connect 将资金转移到已连接帐户的示例:
public function createConnectedAccount()
{
Stripe::setApiKey(config('stripe.sk'));
try {
$account = \Stripe\Account::create([
'type' => 'custom',
'country' => 'US',
'email' => '[email protected]',
'capabilities' => [
'transfers' => ['requested' => true],
],
// Additional account details here
]);
return response()->json(['account_id' => $account->id]);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function initiateTransfer(Request $request)
{
$input = $request->validate([
'account_id' => ['required'],
'amount' => ['required', new CheckBalance],
]);
Stripe::setApiKey(config('stripe.sk'));
try {
$transfer = \Stripe\Transfer::create([
'amount' => $input['amount'] * 100, // Amount in cents
'currency' => 'usd',
'destination' => $input['account_id'],
'description' => 'Transfer to connected account',
]);
return response()->json(['transfer' => $transfer]);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
Route::post('/recharge/initiate-transfer', 'PaymentController@initiateTransfer')->name('stripe.initiate.transfer');
Route::get('/create-connected-account', 'PaymentController@createConnectedAccount')->name('stripe.create.connected.account');
请尝试检查这个