Php 使用条带支付网关向银行帐户发起支付

Php 使用条带支付网关向银行帐户发起支付,php,stripe-payments,Php,Stripe Payments,我正在为一个移动应用程序开发RESTAPI的实现,我需要在这个应用程序中实现直接向客户的银行账户付款的功能。我集成了条带支付网关来完成支付过程,它为 向银行账户或连接账户的借记卡发起支付 <?php require_once('vendor/autoload.php'); \Stripe\Stripe::setApiKey("sk_test_tD8Pxvmv2sOhucPuhqvPDvSP"); $error = ''; $success = ''; if ($_POST) {

我正在为一个移动应用程序开发RESTAPI的实现,我需要在这个应用程序中实现直接向客户的银行账户付款的功能。我集成了条带支付网关来完成支付过程,它为 向银行账户或连接账户的借记卡发起支付

<?php
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("sk_test_tD8Pxvmv2sOhucPuhqvPDvSP");
  $error = '';
  $success = '';

if ($_POST) {

  try {
    if (!isset($_POST['stripeToken']))
      throw new Exception("The Stripe Token was not generated correctly");
    $payment_result=\Stripe\Charge::create(array("amount" => 2000,
                                "currency" => "usd",
                                "card" => $_POST['stripeToken']));

    $success = 'Your payment was successful.';
  }
  catch (Exception $e) {
    $error = $e->getMessage();
  }


}

try{




$Account=\Stripe\Account::create(array(
  "type" => "custom",
  "country" => "US",
  "email" => "demo3455675666gfg5@info.com"
));

if($Account!=NULL){ 

$TokenInfo=\Stripe\Token::create(array(
  "bank_account" => array(
    "country" => "US",
    "currency" => "usd",
    "account_holder_name" => "Mason Wilson",
    "account_holder_type" => "individual",
    "routing_number" => "110000000",
    "account_number" => "000123456789"
  )
));

$external_account_info=$Account->external_accounts->create(array("external_account" => $TokenInfo->id));

$payout_response=\Stripe\Payout::create(array(
  "amount" => 400,
  "currency" => "usd",
  "destination"=>$external_account_info->id
));

}
}
catch(Exception $e)
{
    echo $e->getMessage();exit;
}








?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>Stripe Getting Started Form</title>
        <script type="text/javascript" src="https://js.stripe.com/v1/"></script>
        <!-- jQuery is used only for this example; it isn't required to use Stripe -->
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script type="text/javascript">
            // this identifies your website in the createToken call below
            Stripe.setPublishableKey('pk_test_W2y6W7HcwlV02a8MuCQUHnDn');
            function stripeResponseHandler(status, response) {
                if (response.error) {
                    // re-enable the submit button
                    $('.submit-button').removeAttr("disabled");
                    // show the errors on the form
                    $(".payment-errors").html(response.error.message);
                } else {
                    var form$ = $("#payment-form");
                    // token contains id, last4, and card type
                    var token = response['id'];
                    // insert the token into the form so it gets submitted to the server
                    form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
                    // and submit
                    form$.get(0).submit();
                }
            }
            $(document).ready(function() {
                $("#payment-form").submit(function(event) {
                    // disable the submit button to prevent repeated clicks
                    $('.submit-button').attr("disabled", "disabled");
                    // createToken returns immediately - the supplied callback submits the form if there are no errors
                    Stripe.createToken({
                        number: $('.card-number').val(),
                        cvc: $('.card-cvc').val(),
                        exp_month: $('.card-expiry-month').val(),
                        exp_year: $('.card-expiry-year').val()
                    }, stripeResponseHandler);
                    return false; // submit from callback
                });
            });
        </script>
    </head>
    <body>
        <h1>Charge $10 with Stripe</h1>
        <!-- to display errors returned by createToken -->
        <span class="payment-errors"><?= $error ?></span>
        <span class="payment-success"><?= $success ?></span>
        <form action="" method="POST" id="payment-form">
            <div class="form-row">
                <label>Card Number</label>
                <input type="text" size="20" autocomplete="off" class="card-number" />
            </div>
            <div class="form-row">
                <label>CVC</label>
                <input type="text" size="4" autocomplete="off" class="card-cvc" />
            </div>
            <div class="form-row">
                <label>Expiration (MM/YYYY)</label>
                <input type="text" size="2" class="card-expiry-month"/>
                <span> / </span>
                <input type="text" size="4" class="card-expiry-year"/>
            </div>
            <button type="submit" class="submit-button">Submit Payment</button>
        </form>
    </body>
</html>

条纹入门表格
//这将在下面的createToken调用中标识您的网站
Stripe.setPublishableKey(“pk_测试_W2Y6W7HCWLV02A8MuckuHndn”);
函数stripeResponseHandler(状态、响应){
if(response.error){
//重新启用提交按钮
$('.submit按钮').removeAttr(“已禁用”);
//在表单上显示错误
$(“.payment errors”).html(response.error.message);
}否则{
风险值表$=$(“#付款表”);
//令牌包含id、last4和卡类型
变量标记=响应['id'];
//将令牌插入表单,以便将其提交到服务器
表格$追加(“”);
//并提交
表单$.get(0.submit();
}
}
$(文档).ready(函数(){
$(“#付款表”)。提交(功能(事件){
//禁用“提交”按钮以防止重复单击
$('.submit按钮').attr(“已禁用”、“已禁用”);
//createToken立即返回-如果没有错误,提供的回调将提交表单
Stripe.createToken({
编号:$('.card number').val(),
cvc:$('.card cvc').val(),
exp_month:$('.card expiration month').val(),
exp_year:$('.card expiration year').val()
},stripeResponseHandler);
返回false;//从回调提交
});
});
条纹收费10美元
卡号
CVC
有效期(年月日)
/ 
付款
在执行上述代码段时,它会生成一个错误,该错误表示

无此类外部账户:ba_1chy2dvygpg6lmyTqdcu53b


请建议我使用条带支付网关向银行帐户支付的适当解决方案。

您创建支付的呼叫失败,因为您是在条带帐户上执行,而不是在连接的条带帐户上执行

您需要在支付通话中添加一个条带帐户标题,因为银行帐户附加到连接的帐户,而不是您自己的条带帐户

$payout_response=\Stripe\Payout::create(array(
  "amount" => 400,
  "currency" => "usd",
  "destination"=>$external_account_info->id
),
  array("stripe_account"=>$Account->id)
);
更多信息请参见此处

退一步说,支付给银行账户的资金来自Connect账户的余额。要将资金转入连接账户的余额,您需要使用此处描述的方法之一,最有可能的方法是使用目的地费用或单独的费用和转账