Monday, September 18, 2017

Stripe Using Connect with Standard Accounts | Stripe Create Standard Account

1 Login to your stripe account and navigate to https://dashboard.stripe.com/account/applications/settings and follow below steps:








2. Copy Client ID and follow below PHP script (which will redirect target users to Stripe application page to fill up their personal details to create and account with Stripe):



<?php
$client_id = "ca_BPnCyPD...........ODApFdHyTXHbwQ";
$auth_url = "https://connect.stripe.com/oauth/authorize?".
    "response_type=code&client_id=$client_id&scope=read_write".
    "&redirect_uri=".rawurlencode("http://localhost/ci/dragon71/stripe/callback.php").
    "&state=".md5(trim(true));
header("Refresh:0; url=$auth_url");

3. After completing procedures there, Stripe will redirect back to our target redirect URL as below:


http://localhost/ci/dragon71/stripe/callback.php?state=c4ca4238a0b923820dcc509a6f75849b&scope=read_write&code=ac_BQGZyHtVkFbOFYhNPTlAdbZeZcMutzec

If fails then:

http://localhost/ci/dragon71/stripe/callback.php?state=c4ca4238a0b923820dcc509a6f75849b&error=access_denied&error_description=The+user+denied+your+request

4. One thing we forgot, have to collect our API Key to request API call, navigate to https://dashboard.stripe.com/account/apikeys to collect your API Key's.




5. After successful redirect back, it's time to collect access token to procedure further. 


<?php
include_once "curl.php";

$api_key = "sk_test_eXF4.........jWrcHK95rwj";
$url = "https://connect.stripe.com/oauth/token";

$params = array(
    "code" => $_GET["code"],
    "grant_type" => "authorization_code"
);

$headers[] = "Authorization: Bearer $api_key";
$headers[] = "Content-Type: application/x-www-form-urlencoded";

$result = CurlExecutor::execute($url, "POST", null, $params, $headers);
$result["response"] = json_decode($result["response"]);
CurlExecutor::prettyPrint($result);

Successful output would be like below:


Array
(
    [code] => 200
    [response] => stdClass Object
        (
            [access_token] => sk_test_oWtb.........xb4tLBXqZmh
            [livemode] => 
            [refresh_token] => rt_BQGsyumxyAoDH....................aPMt5MvpprSnpwD
            [token_type] => bearer
            [stripe_publishable_key] => pk_test_xHhgw.........zfo0QYltBB
            [stripe_user_id] => acct_1B3........3aeEh
            [scope] => read_write
        )

)

Use "access_token" (actually it is "Secret key" for API), you can use this Key to process all your transactions.

And list of your connected account is below:




No comments:

Post a Comment