1

Step 1: First Connect with PLAID with Stripe and using public key receive public_token and account_id

<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>

 <script>
 var linkHandler = Plaid.create({
    clientName: 'Scholastic Expeditions',
    countryCodes: ['US'],
    env: 'sandbox',
    // Replace with your public_key from the Dashboard
    key: '071e075d1d6a109d6g2adb12c426c08',
    product: ['auth'],
    // Optional, use webhooks to get transaction and error updates
    webhook: 'http://test.code.org',
    // Optional, specify a language to localize Link
    language: 'en',
    onLoad: function() {
      // Optional, called when Link loads
    },
    onSuccess: function(public_token, metadata) {
        //account_id = metadata.account_id
        account_id = metadata.accounts[0].id
        sendBackendServer(public_token,account_id);
    },
    onExit: function(err, metadata) {
        // The user exited the Link flow.
        if (err != null) {
            // The user encountered a Plaid API error prior to exiting.
        }
    }
});
document.getElementById('linkButton').onclick = function() {
   linkHandler.open();
};
</script>

Step 2: On Serverside receive access_token and stripe_token using curl

$plaid_client_id = '5d82ff239085b9001306139c';
$public_token = $_REQUEST['public_token'];
$plaid_secret = '565228fd7511c2d1ea2d1bc46eab15';
$env = 'sandbox';
$account_id = $_REQUEST['account_id'];


$headers[] = 'Content-Type: application/json';

$params = array(
    "client_id" => $plaid_client_id,
    "secret" => $plaid_secret,
    "public_token" => $public_token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://" . $env . ".plaid.com/item/public_token/exchange");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 80);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

if(!$result = curl_exec($ch)) {
    trigger_error(curl_error($ch));
}
curl_close($ch);

$jsonParsed = json_decode($result);

$btok_params = array(
    'client_id'    => $plaid_client_id,
    'secret'       => $plaid_secret,
    'access_token' => $jsonParsed->access_token,
    'account_id'   => $account_id
 );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://" . $env . ".plaid.com/processor/stripe/bank_account_token/create");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($btok_params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 80);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

if(!$result = curl_exec($ch)) {
    trigger_error(curl_error($ch));
}
curl_close($ch);

$btoken = json_decode($result);

$stripe_bank_account_token = $btoken->stripe_bank_account_token;

Step 3 : using stripe_bank_account_token charge amount

$charge = Stripe_Charge::create(array(       
    "amount" => $totalPayAmount,
    "currency" => 'USD',
    "source" => $tokenID,
    "description" => 'test_account')              
);

My Question are: 1. On production may be bank verification and charge takes time so How can we handle it at our end. 2. How can I automatically re-charge amount automatically from user account

Sudhir
  • 835
  • 11
  • 31
  • @shivani Can you please help me to find out solutions – Sudhir Sep 25 '19 at 10:22
  • @koopajah Can you please help me to find out solutions – Sudhir Sep 25 '19 at 10:22
  • 1
    I would recommend that you contact Stripe's support team directly here. Your questions are not about code, they are about the ACH product they offer. You can contact them directly here: https://support.stripe.com/contact But the problem here is that you are charging the token instead of saving it on a customer first: https://stripe.com/docs/api/customer_bank_accounts/create – koopajah Sep 30 '19 at 17:04
  • **[You should not switch off `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Oct 02 '19 at 22:42
  • @sahil-dhankhar can you please help me on this question – Sudhir Oct 11 '19 at 11:44

0 Answers0