I have built a platform with buyers and sellers and now I would like to integrate payments. I came across Stripe, it is quite easy and straight forward to use.
However, I found the documentation to be lacking since I want to implementation whereby the seller doesn't have to create a stripe account in order to get paid by the buyer. What Stripe offers is a solution they call; stripe connect.
Stripe connect has three options; Standard, Express and Custom.
The solution that makes sense for my specific use case is the custom option. From the documentation, they have this code snippet;
Stripe.api_key = 'STRIPE_SECRET_KEY'
account = Stripe::Account.create({
country: 'US',
type: 'custom',
requested_capabilities: ['card_payments', 'transfers'],
})
The above, they write, is used to create a custom account. Quite frankly, there isn't much to work with. Has anyone developed something that I am trying to implement. Assistance in this regard would really be helpful.
I have implemented Express Stripe connect. This is an helper that I have written;
module ApplicationHelper
# Express Stripe url
def stripe_url
"https://dashboard.stripe.com/express/oauth/authorize?response_type=code&client_id=#{ENV["STRIPE_CONNECT_CLIENT_ID"]}&scope=read_write"
end
# Express Stripe Implementation
def stripe_connect_button
link_to stripe_url, class: "stripe-connect" do
content_tag :span, "Connect With Stripe"
end
end
end
I write <%= stripe_connect_button %>
in the .erb
file and it rendered properly. I am able to go through the entire process.
I would like to have a somewhat similar approach but for Custom Stripe Connect because with the above implementation, I had to create a stripe account as a seller.
I was able to test the custom stripe account creation using curl
based on this
With curl
it is like so;
curl https://api.stripe.com/v1/accounts \
-u STRIPE_SECRET_KEY: \
-d country=US \
-d type=custom \
-d "requested_capabilities[]"=card_payments \
-d "requested_capabilities[]"=transfers
The above returns json and I copy the id
which an account_id
. I use this id in another curl request;
curl https://api.stripe.com/v1/account_links \
-u STRIPE_SECRET_KEY: \
-d account= #{id} \
-d refresh_url="https://example.com/reauth" \
-d return_url="https://example.com/return" \
-d type=account_onboarding
This returns json that looks like so;
{
"object": "account_link",
"created": 1594988541,
"expires_at": 1594988841,
"url": "https://connect.stripe.com/setup/c/AUyum7LCw4cV"
}
Then I visit the url:
https://connect.stripe.com/setup/c/AUyum7LCw4cV
to do the on-boarding. I have successfully been able to create a stripe connect custom account
.
However, I want to translate this flow to RubyOnRails
.
So, my question is, how do I cause the below code snippet to initiate account creation when a Seller
clicks a button (Connect To Stripe
) ?
Stripe.api_key = STRIPE_SECRET_KEY
account = Stripe::Account.create({
country: 'US',
type: 'custom',
requested_capabilities: ['card_payments', 'transfers'],
})
In the Express Stripe Connect
implementation, I had a url
that I was passing to the button. With the above, I have no url to work with.