Create Custom Stripe Connect Accounts - stripe-payments

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.

The code you share would create a Custom account on behalf of the seller in the API. This is only the first step before you can accept payments on their behalf and send funds to their bank account.
There are a lot of regulations around the flow of funds and the information you need to collect from the seller and you can't simply send $100 to a bank account in the US without completing those steps. Stripe covers in details all the information that needs to be collected depending on the type of business you are building and the countries you are going to operate in. You can read more about this here: https://stripe.com/docs/connect/required-verification-information
Collecting this information reliably can be fairly tricky early on for a project like yours. Similarly, rules and regulations evolve regularly, requiring you to collect more details for new users, backfill some missing information and do extra reporting.
This is why Stripe built their Connect Onboarding hosted page so that you can defer the collection of all information to them. You can read more about this here: https://stripe.com/connect/onboarding
Using Connect Onboarding is likely to be the best solution for your business as you can easily enable your sellers to provide the relevant information without having to own a Stripe account directly while you focus on the core parts of your own business.

Related

Creating a subscription using bank account number using stripe js in node js

I have created subscription by accespting credit/debit card number, exp month, exp year and cvc from front end angular app and creating
Customer
Product
Product Price
Payment Method
Subscription
In payment method i provide following details:
async function createPaymentMethod(data) {
let body = {
type: 'card',
card: {
number: data.card?.number,
exp_month: data.card?.exp_month,
exp_year: data.card?.exp_year,
cvc: data.card?.cvc
}
};
return await stripe.paymentMethods.create(body);
}
Now i want to create payment method but want to use customer's bank account number but i am unable to find a way to do it. I want to add "type: bank_account"
Note: I am using Strip JS and Node JS. All of this I want to do on server side i.e node js
Collecting Credit Card server-side is a bad idea, since you will expose yourself to the burden on PCI-Compliance. You would want to review Stripe's Integration Security Guide. Generally you would want to use client-side SDK to collect credit card information instead.
To the question of a bank account, it depends on which specific PaymentMethod you're gonna use (which country's bank transfer?) Ie. If you are talking about ACH in the US, you should follow the ACH Guide. Similarly it will collect bank account information client-side in exchange of a token, then passing it up to your back end.

Angular/node.js Stripe Checkout Integration (1 account to facilitate payments from third party payer to third party receiver)

Man, I have been at this for some days and can't find a good solution to this. I want to use my account (via public key and private key) to facilitate payments from one account to another (nothing will be going into my account). On the front-end I have:
checkout(amount) {
const strikeCheckout = (<any>window).StripeCheckout.configure({
key: environment.PRODUCTION==='true'?stripeLiveClientId:stripeTestClientId,
locale: 'auto',
token: (stripeToken: any) => {
if(stripeToken){
console.log(stripeToken)
this.createCharge(stripeToken,amount)
}
}
});
strikeCheckout.open({
name: 'Camel Stripe',
description: 'Stripe Checkout',
amount: amount
});
}
Just a small snipet, but essentially this just captures the credit card and email and ensures it is a valid credit card and then makes a stripe token. I then pass this token to the node backend and do:
stripe.paymentIntents.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
}).then(charge => {
return res.json({ success: true, message: 'Success', result: charge })
}).catch(error => {
res.status(400).json({ success: false, status: 400, message: error });
});
//})
};
No matter how I structure it, it always end's up getting the payment to my account, the account with the public/private key. Does anyone know a way I can use this token since it has the necessary information, and send the money to another account?
You can't accept payments and move the funds into a completely different Stripe account unless you're using Connect.
To piggy back on Paul's comment, after much research on Stripe Connect I wanted to share my findings. Please note this is specific to my use case and is using angular/express.
Connect offers multi-party payments, meaning you can receive funds from 1 user, then route them into another users account. You will need a stripe connect account. After that you connect an account, aka create account. They offer 3 account types all these account types need to be
Custom: basically is if you don't want the account you're routing to to see anything stripe related, meaning it is white labeled and the user has no dashboard or view of what is going on in the background.
Standard(the one I chose): this account will have a full stripe dashboard, it has all the functionality that an account would have that you make on your own. You will get a unique account id relevant to your specific connect account environment, on their end, they will have multiple account ids depending on how many other connects they are connected to, or if it is an already existing account. You will need to use this api to get the link to have them verify information before they are integrated into your connect environment account link api
Express: they will have a slimmed down version of a dashboard, it is similar to standard with less functionality
At this point you're ready to start routing payments. I did angular on the front-end, here is an example basically this simply creates a stripeToken, which is a verification that the card data is valid. You need to pass this to a backend to make use of it, this will not create any charges.
On the backend, I used express, you use the charge api You pass the stripeToken as the source attribute. One important step is to add the stripe account id you see in your connected accounts dashboard. It should look similar to:
stripe.charges.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
},{
stripeAccount:'{{acctId}}'
})
This should be sufficient to get your payments routing to the necessary account while leveraging a simple UI checkout.
One thing to note about the charges API, this is an older API and has less functionality. For my use case (US CA only with only card payments) it is sufficient. If you have a more complicated use case, or maybe your app is for heavy prod use to many users you should look into payment intents.

Possible to query a Stripe managed account's balance?

I've gone through the docs and haven't been able to spot a way to query balance info for Stripe managed accounts. Here's the use case: a 3rd party sets up a managed account through my Stripe Connect enabled platform; I create some charge objects on their account after a few customers buy goods/services (so their balance is now positive); now they want a payout BUT I want to query their balance before issuing the transfer to ensure they're not asking for more than is in their account.
Surely I'm missing something obvious. Thanks in advance.
So for Ruby, based on Ywain's answer, I figured that instead of doing what's documented:
Stripe.api_key = CONNECTED_STRIPE_ACCOUNT_SK
Stripe::Balance.retrieve
a better way, that is not documented, is to do:
Stripe::Balance.retrieve(stripe_account: CONNECTED_STRIPE_ACCOUNT_ID)
as long as the current api_key is your platform account with the managed accounts option enabled.
PHP
\Stripe\Balance::retrieve([
'stripe_account' => CONNECTED_STRIPE_ACCOUNT_ID
]);
Python
stripe.Balance.retrieve(
stripe_account=CONNECTED_STRIPE_ACCOUNT_ID
)
Ruby
Stripe::Balance.retrieve(
:stripe_account => CONNECTED_STRIPE_ACCOUNT_ID
)
Node
stripe.balance.retrieve({
stripe_account: CONNECTED_STRIPE_ACCOUNT_ID
}, function(err, charge) {});
You should be able to do this by simply issuing a balance retrieval call while authenticating as the connected account, e.g.:
curl https://api.stripe.com/v1/balance \
-H "Authorization: Bearer {PLATFORM_SECRET_KEY}" \
-H "Stripe-Account: {CONNECTED_STRIPE_ACCOUNT_ID}"

Stripe API error when passing application_fee

I am trying to collect an application fee using the Stripe API. I am sure I am missing something in the request.
Stripe complaints that it needs either of these: OAuth key, the Stripe-Account header, or the destination parameter.
I am passing in the Stripe-Account header.
Here is my curl request:
curl https://api.stripe.com/v1/charges \
-u sk_test_<key>: \
-H "Stripe-Account: acct_<key>" \
-d amount=2000 -d currency=usd -d capture=true \
-d card=tok_<key> -d description="curl" -d application_fee=48
Here is the response I get:
{
"error": {
"type": "invalid_request_error",
"message": "Can only apply an application_fee when the request is made on behalf of another account (using an OAuth key, the Stripe-Account header, or the destination parameter).",
"param": "application_fee"
}
}
What can I try next?
To add my experience of this issue to the comments above – when you include an application fee in the request, Stripe expects that you will be charging a customer on behalf of a connected account. The application fee is the amount that should go to your platform account, as your fee for the service you provide.
Stripe throws this error if it believes that the account being paid is the platform account, and therefore it makes no sense to process a separate application fee to the same account. Ways this can happen include passing in your platform account number instead of a connected account number in the request, or a destination parameter that is set to null.
The solution is to double check the account you are making payment to is not your platform account, or not include the application fee if the charge is going to your platform. I would add a link to the relevant part of the documentation, but I'm not aware of this being covered anywhere.
This happened to me when I accidentally had a nil value for the recipient's stripe account number.
The solution was to make sure destination was a valid stripe account code: e.g. "acct_1HtSHv7fgYVxT5fZ"
Stripe.api_key = 'sk_test_4eC39kjhkhgkhlhj1zdp7dc'
payment_intent = Stripe::PaymentIntent.create({
payment_method_types: ['card'],
amount: #amount_minor_unit,
currency: #currency,
application_fee_amount: 123,
transfer_data: {
destination: #stripe_account,
},
})
Stripe::InvalidRequestError (Can only apply an application_fee_amount when the
PaymentIntent is attempting a direct payment (using an OAuth key or Stripe-Account header)
or destination payment (using `transfer_data[destination]`).)
Once I had the correct value for #stripe_account (instead of nil), the above code worked

In the Authorizenet SDK version 1.1.8 for PHP Is there a way to charge a card using a customer payment profile?

I have been up and down through the SDK code and have the ability to add customer profiles and payment profiles for them but I can't see anywhere, where I can charge a card or create a subscription from a customer profile and customer payment profile. Does anyone have an answer for this for either the create subscription, or charge a card, using the PHP SDK. Please understand, giving me an interactive web example using AuthorizeNet's web API is not helpful here. The requirements are that it has to be done through the PHP SDK as we cannot have card user interaction past the point of the customer profile and customer payment profile creation.
First off need to define the normal credentials used for SDK requests
if (!defined("AUTHORIZENET_API_LOGIN_ID")) define("AUTHORIZENET_API_LOGIN_ID", {authorizenet_api_login_id};
if (!defined("AUTHORIZENET_TRANSACTION_KEY")) define("AUTHORIZENET_TRANSACTION_KEY", {authorizenet_transaction_key};
Then create the transaction and set the fields.
$transaction = new AuthorizeNetTransaction;
$transaction->amount = $amount;
$transaction->customerProfileId = $customerProfileId;
$transaction->customerPaymentProfileId = $customerPaymentProfileId;
// next line may be optional depending on your situation
$transaction->customerShippingAddressId = $customerShippingAddressId;
Then process the transaction
$request = new AuthorizeNetCIM;
$response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
if ($response->xml->messages->resultCode=="Ok") echo "It Was Approved"
;

Resources