I aim to transfer my Strype funds to someone else’s bank account.I am trying the following approach.
// 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());
}
}
In the route file:
Route::put('/recharge/initiate-Transfer', 'initiateTransfer')->name('strype.initiate.transfer');
Route::get('test/bank-account', 'generateBankAccountToken')->name('strype.test.bank');
After calling the strype.test.bank
route I am getting the token: btok_1PVXsvAzd6Qck0TGa8chJlfd
.
However, after applying the token on the initiateTransfer
function, I am getting the following error.
StripeExceptionInvalidRequestException {#1605 ▼ // appHttpControllersPaymentControllerStripeController.php:156
#message: "No such destination: 'acct_1MQccXIQ2pUmxoSJ'"
#code: 0
.........................................