douliedu335997 2016-10-22 15:06
浏览 66
已采纳

如何使用条带创建用户银行帐户?

Using following php code I can easily add a bank account of my users with additional information to my stripe account.

<?php
try {
require_once('vendor/autoload.php');
 Stripe\Stripe::setApiKey("sk_test_code"); 

 $account = \Stripe\Account::create(
    array(
        "country" => "US", 
        "managed" => true,
        "email" => "email@gmail.com",
        "legal_entity" => array(
            'address' => array(
                'city' => 'Carlifonia', // 
                'country' => 'US',
                "line1" => 'Address line 1',  
                "line2" => 'Address line 2', 
                "postal_code" => '90046', 
                "state" => 'Denver' // 
            ),
            'business_name' => '',
            'business_tax_id' => '',
            'dob' => array(
                'day' => '01', 
                'month' => '01', 
                'year' => '1990', 
            ),
            'first_name' => 'Test Lynn First Name',
            'last_name' => 'Test Lynn Last Name',
            //'personal_id_number' => '000000000',
            'ssn_last_4' => '4444', 
            'type' => 'individual' 
        ),
        'tos_acceptance' => array(
            'date' => time(),
            'ip' => $_SERVER['REMOTE_ADDR']
        ),
        'transfer_schedule' => array(
            "interval" => 'weekly', 
            "weekly_anchor" => 'sunday'
        ),
        'external_account' => array(
            "object" => "bank_account",
            "country" => "US",
            "account_holder_type" => 'individual', r
            "routing_number" => "111000025", 
            "account_number" => "000123456789" 
        )
    )
);

    //send the file, this line will be reached if no error was thrown above
    echo "<h1>Account ID = ".$account['id']."</h1>";
    echo "<h1>Secret Key = ".$account['keys']['secret']."</h1>";
    echo "<h1>Publish Key = ".$account['keys']['publishable']."</h1>";

}
//catch the errors in any way you like

catch(Stripe_CardError $e) {
    print_r($e);
}

catch (Stripe_InvalidRequestError $e) {
// Invalid parameters were supplied to Stripe's API
    print_r($e);

} catch (Stripe_AuthenticationError $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
    print_r($e);

} catch (Stripe_ApiConnectionError $e) {
// Network communication with Stripe failed
    print_r($e);
} catch (Stripe_Error $e) {
    print_r($e);
// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {
    echo '<pre>';
    $e_json = $e->getJsonBody();
    echo $error = $e_json['error']['message'];
    echo '</pre>';
// Something else happened, completely unrelated to Stripe
}
?>

The html form is look like this :

<form role="form" id="bank-payment-form" method="POST" action="<?php echo esc_url(SITE_URL.'test-bank-create') ?>">
    <div class="row">
        <div class="col-md-12"><h3>Identity Verification<hr/></h3></div>
        <div class="bank-errors"></div>
        <div class="form-group col-xs-12 col-sm-4 col-md-4">
            <label class="control-label" for="date-time">Date Of Birth</label>
            <select class="form-control day">
                <option value="">--Select Day--</option>
                <?php
                for ($d = 1; $d <=31; $d++) {
                    echo "<option value='$d'>$d</option>";
                }
                ?>
            </select>
        </div>
        <div class="form-group col-xs-12 col-sm-4 col-md-4">
            <label class="control-label" for="date-time">&nbsp;</label>
            <select class="form-control month">
                <option value="">--Select Month--</option>
                <?php
                for ($m = 1; $m <=12; $m++) {
                    echo "<option value='$m'>$m</option>";
                }
                ?>
            </select>
        </div>
        <div class="form-group col-xs-12 col-sm-4 col-md-4">
            <label class="control-label" for="date-time">&nbsp;</label>
            <select class="form-control year">>
                <option value="">--Select Year--</option>
                <?php
                for ($i =2010; $i > 1900  ; $i--) {
                    echo "<option value='$i'>$i</option>";
                }
                ?>
            </select>
        </div>
        <div class="form-group col-xs-12 col-sm-12 col-md-12">
            <label class="control-label" for="date-time">Address</label>
            <input type="text" placeholder="Address 1" class="form-control address1" value="">
        </div>
        <div class="form-group col-xs-12 col-sm-12 col-md-12">
            <input type="text" placeholder="Address 2 (optional)" class="form-control address2" value="">
        </div>
        <div class="form-group col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" for="date-time">Country</label>
            <input type="text" value="US" disabled class="form-control country">
            <input type="hidden" value="USD" data-stripe="country" disabled class="form-control" data-stripe="country">
        </div>
        <div class="form-group col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" for="date-time">State</label>  
            <select class="form-control state" id="area" required>
            <?php
            $get_location = mysqli_query($conn, "SELECT * FROM product_area");
            if(mysqli_num_rows($get_location) == 0 ) {
                $choose = 'No state found';
            } else {
                $choose = 'Choose State';
            }
            ?>
            <option value=""><?php echo $choose; ?></option>
            <?php                                         
            while($get_location_result = mysqli_fetch_array($get_location) ) {
                $location_id = (int) $get_location_result['parea_id'];
                $location_name = htmlspecialchars($get_location_result['parea_name']);
                echo "<option value='$location_id'>$location_name</option>";
            }
            ?>                    
            </select>
        </div>
        <div class="form-group col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" for="date-time">City</label>  
            <select id="sub_area" class="form-control city">
                    <option value="">--Select City--</option>
            </select>
        </div>
        <div class="form-group col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" for="date-time">Zip Code</label>
            <input type="text" value="<?php echo $zip_db; ?>" placeholder="Zip Code" class="form-control zip">
        </div>

        <div class="form-group col-xs-12 col-sm-12 col-md-12">
            <label class="control-label" for="date-time">SSN Number</label>
            <input type="text" placeholder="SSN Number" class="form-control ssn" value="">
            <small>Your SSN is used to verify your identity.</small>
        </div>
        <div class="col-md-12"><h4><b>Funds Recipient</b></h4></div>
        <div class="form-group col-xs-12 col-sm-12 col-md-12">
            <select class="form-control account_holder_type">
                <option value="">--Select Account Holder Type--</option>
                <option value="individual">Individual</option>
                <option value="company">Company</option>
            </select>
        </div>
        <div class="col-md-12"><h4><b>Bank Account</b></h4></div>
        <div class="form-group col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" for="date-time">Routing Number</label>
            <input type="text" class="form-control routing_number" value="" placeholder="123456789">
            <small>Your routing number will be 9 digits</small>
        </div>                    
        <div class="form-group col-xs-12 col-sm-6 col-md-6">
            <label class="control-label" for="date-time">Account Number</label>
            <input type="text" class="form-control account_number" value="" placeholder="">
            <small>Your routing number will be 9 digits</small>
        </div>                    
        <div class="col-md-6 col-sm-6 col-xs-12">
            <input type="submit" value="Verify Identity" class="submit btn btn-booking">
        </div>                    
        <?php } ?>    
    </div>                     
</div>    
</div>
</form> 

I saw stripe.js. They are using following js code to add bank account :

Stripe.bankAccount.createToken({
  country: $('.country').val(),
  currency: $('.currency').val(),
  routing_number: $('.routing-number').val(),
  account_number: $('.account-number').val(),
  account_holder_name: $('.name').val(),
  account_holder_type: $('.account_holder_type').val()
}, stripeResponseHandler);

But you see that, In my html form I have addition fields e.g date of birth.

My Question is how can add a bank account of a user using this stripe.js with all my html form fields ?

  • 写回答

1条回答 默认 最新

  • duanmangxie7131 2016-10-23 21:32
    关注

    Fields needed for the legal entity properties of a managed account are not something you can pass directly via Stripe.js.

    What you can do here is create a bank account token, append it to your form, which contains other information, and then submit that form to your back-end for processing.

    Here's how it'd work: Setup a handler to listen on form submit or on click of your submit button, use this to trigger your Stripe.bankAccount.createToken call.

    In the stripeResponseHandler callback of your createToken call, append a hidden input with the name stripeToken to the target form, then submit the form.

    The form will be passed to your backend with the bank account token as well as any other form fields you've created between your <form></form> tags and named, which you can then retrieve with php (e.g. $_POST['stripeToken'] for the bank account token you've appended, or $_POST['dob-year'] if you had a field with an attribute name="dob-year").

    You can see the basic idea in action here: https://jsfiddle.net/pay62y2f/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂