Monday, 7 September 2015

On-Boarding Feature Of Stripe

When User Wants to create Instant account for Payment Process On Stripe, And App Owner wants to add new user under his Current Stripe Account to manage all his app users.

Step 1 :- To Start this, We need a client_id from stripe account. below the screen shot from when we can get client Id in Stripe account dashboard.

Stripe Dashboard => Account Setting => Connect tab => Client Id



Step 2 :- Now add this Client Id in below link where you want to add on-boarding link.

https://connect.stripe.com/oauth/authorize?response_type=code&client_id=client_id&scope=read_write

This above link will take user to Stripe On-boarding Form, From where user need to fill all the info related to stripe account.


Step 3 :- Now, The user will then be redirected back to your site (specifically to your redirect_url), passing along either an authorization code or an error ( if the connection request was denied)
So For this, we need to add redirect url into our stripe account. See Below :

Stripe Dashboard => Account Setting => Connect tab => Redirect URLs: 


Dynamically Setting the redirect URI 


For security purposes, Stripe will only redirect a user to a pre-defined uri. However, Connect allows you to define more than one redirect URI, which can be used to further customize the user's experience. For example, you could have some of your users redirected back to "https://sub1.example.com" and others sent to "https://sub2.example.com", each with custom behavior.

First, In Your platform setting (Stripe Dashboard => Account Setting => Connect tab => Redirect URLs:), set the redirect URIs to a comma-separated list of allowed URIs. Second, add a redirect_uri parameter to your authorization request with a value found in your comma-separated list.

https://connect.stripe.com/oauth/authorize?response_type=code&client_id=client_id&scope=read_write&redirect_uri=custom_redirect_uri


Step 4 :- After the user has connected

When the user arrives at Stripe, they'll be prompted to allow or deny the connection to your platform, and will then be sent to your redirect_uri page. In the URL, Stripe will pass along an authorization code:

your_redirect_uri?scope=read_write&code=AUTHORIZATION_CODE

Step 5 :- Get Stripe Credentials from authorization code

api_key = Secret Key ( Stripe Dashboard =>Account Setting => Api Keys)

client_id = client id ( Stripe Dashboard => Account Setting => Connect => Client Id )


options = {:site => 'https://connect.stripe.com', :authorize_url => '/oauth/authorize', :token_url =>'/oauth/token', :raise_errors => false}

client = OAuth2::Client.new(client_id, api_key, options)  ( For this you will need to add oauth2 gem in your gemfile)

resp = client.auth_code.get_token(AUTHORIZATION_CODE, :params => {:scope => 'read_write'})

Stripe will return a response containing the authentication credentials for the user :

{
  "token_type": "bearer",
  "stripe_publishable_key": PUBLISHABLE_KEY,
  "scope": "read_write",
  "livemode": false,
  "stripe_user_id": USER_ID,
  "refresh_token" : REFRESH_TOKEN,
  "access_token" : ACCESS_TOKEN
}

and if there was a problem, they'll instead an error.

{
  "error": "invalid_grant",
  "error_description": "Authorization code does not exist: AUTHORIZATION_CODE"
}


Stripe provided some more options in this on-boarding process. Use below link for your extra need in app.

https://stripe.com/docs/connect/standalone-accounts#deferred-accounts







No comments:

Post a comment