Accounts
– https://stripe.com/docs/connect/accounts
## Connect
1. Standard
– https://stripe.com/docs/connect/standard-accounts
– After connect
“`
curl -X POST https://connect.stripe.com/oauth/token -d client_secret=sk_test_ZP9WbGeRb5CFvs4kWDBPR8Jc -d code=ac_ER68Fn6EbyR7TxEldQDHzf291Qec1GxT -d grant_type=authorization_code
“`
– Successfull
“`json
{
“access_token”: “sk_test_yyomURbMIhHSqTfMt2Nd1ZD8”,
“livemode”: false,
“refresh_token”: “rt_ER6AyW6ZyNVytV1IXDW0WMaT0vxMJZUaz4pXCo5TzDuYY9VL”,
“token_type”: “bearer”,
“stripe_publishable_key”: “pk_test_12KT0HWOwhOqnoYdk0hHAAC3”,
“stripe_user_id”: “acct_1DoTJvEUH4GKXr6Y”,
“scope”: “read_write”
“`
## Charges
Official Document : https://stripe.com/docs/connect/charges
**Direct charges:**
– The connected account is responsible for the cost of the Stripe fees, refunds, and chargebacks
– The payment itself appears as a charge in the connected account, not in your platform account
– Charges directly increase the connected account’s balance
– Your platform’s balance is only increased via application fees
**Destination charges**
– Your platform account is responsible for the cost of the Stripe fees, refunds, and chargebacks, handling these for the connected account
– The payment itself appears as a charge in your platform account, followed by an automatic allocation to the connected account, which decreases your platform’s balance and increases the connected account’s balance
– Platform fees are earned by allocating less than the entire charge amount to the connected account
**Separate charges and transfers**
The third approach is to create charges on the platform account and then separately transfer funds to the connected account. This approach is similar to creating destination charges, but provides greater flexibility over the flow of funds at the cost of a more complicated integration.
Using this approach:
– Your platform account is responsible for the cost of the Stripe fees, refunds, and chargebacks, handling these for the connected account
– The payment itself appears as a charge in your platform account, with a separate, manual allocation to the connected account, which decreases your platform’s balance and increases the connected account’s balance
– Funds from charges can be allocated to more than one connected account
– Platform fees are earned by allocating less than the entire charge amount to the connected account
#!/usr/bin/env ruby
require ‘stripe’# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = “sk_test_ZP9WbGeRb5CFvs4kWDBPR8Jc” # platform api key
# Stripe.api_key = “sk_test_yyomURbMIhHSqTfMt2Nd1ZD8”
CONNECTED_STRIPE_ACCOUNT_ID = “acct_1DoTJvEUH4GKXr6Y”charge = Stripe::Charge.create({
:amount => 100,
:currency => “eur”,
:source => “tok_1DyERbLvrMKW6bhfe3ykifOj”,
:description => “Pay for practioner #{CONNECTED_STRIPE_ACCOUNT_ID}”
# :destination => {
# :account => “acct_1DoTkkLvrMKW6bhf”,
# }
},
:stripe_account => “#{CONNECTED_STRIPE_ACCOUNT_ID}”
)puts charge.inspect
Payment Form :
Official : https://stripe.com/docs/stripe-js
Demo : https://jsfiddle.net/misostack/qrkp1uy9/9/
Summary: Có 3 cách để tích hợp stripe payment dạng direct charge cho application.
1.User tự config api key cho app của mình thông qua app. Khi process payment hệ thống đọc api key của user và process direct payment cho user khi customer thanh toán
2.User authorize connect với account stripe của app. App lưu lại stripe_account_id để khi process payment hệ thống dùng api_key của app thực hiện direct payment cho user khi customer thanh toán
3.User authorize connect với account stripe của app. App lưu lại access_token, refresh token của user. Khi process payment hệ thống dùng access_token của user thực hiện direct payment cho user khi customer thanh toán.




