Stripe 动态付款

2024-02-20

我正在与 Stripe 作斗争。我正在使用 PHP,并且正在尝试建立一个简单的商店,没有 CMS。想知道如何将金额传递到 charge.php,以便我可以对不同的产品收取不同的金额。这里是我的代码:

$charge = Stripe_Charge::create(array(
      'customer' => $customer->id,
      'amount'   => 1900;,
      'currency' => 'gbp'
  ));

这是来自index.php的代码 - 我想向客户收取下面表格中“数据量”中的任何费用。不太确定该怎么做。

<form action="inc/charge.php" method="POST">
    <script
            src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="<?php echo $stripe['publishable_key']; ?>"
            data-amount="1900"
            data-currency="GBP"
            data-name="Pure - Tumblr Theme"
            data-allow-remember-me="false"
            data-description="Premium Tumblr Theme"
            data-image="/128x128.png">
          </script>
</form>

更全面的是,从index.php 到charge.php,而不是相反。

<?php
 #set your variables
 $amount       = 500;
 $name         = 'My Company';
 $currency     = 'gbp';
 $description  = 'Value Plan';
 $uid          = get->your->uid;
 $email        = get->your->email;
?>

<center><form action="../charge.php" method="post">
<!-- make these hidden input types for the post action to charge.php -->
<input type="hidden" name="amount"      value="<?php echo $amount?>">
<input type="hidden" name="name"        value="<?php echo $name;?>">
<input type="hidden" name="currency"    value="<?php echo $currency;?>">
<input type="hidden" name="description" value="<?php echo $description;?>">
<input type="hidden" name="uid"         value="<?php echo $uid;?>">
<input type="hidden" name="email"       value="<?php echo $email;?>">

<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"

        data-key =           "<?php echo $stripe['publishable_key']; ?>"
        data-amount =        "<?php echo $amount;?>"
        data-name =          "<?php echo $name;?>"
        data-currency =      "<?php echo $currency;?>"
        data-description =   "<?php echo $description;?>"
        data-email =         "<?php echo $user->data()->email; ?>"
        data-billing-address =     "true"
        data-allow-remember-me =   "false"
        >

</script>
</form></center>

然后在charge.php中你可以调用你隐藏在index.php中的输入值

<?php
$token        = $_POST['stripeToken'];
$email        = $_POST['email'];
$uid          = $_POST['uid'];
$currency     = $_POST['currency'];
$amount       = $_POST['amount'];
$description  = $_POST['description'];

#This is the standard try catch block stripe suggests
try{
$charge = Stripe_Charge::create(array(
"amount"        => $amount,
"currency"      => $currency,
"customer"      => $charge_to,
"description"   => $description
));

} catch(Stripe_CardError $e) {

$error = $e->getMessage();
// Since it's a decline, Stripe_CardError will be caught
$body = $e->getJsonBody();
$err  = $body['error'];

print('Status is:' . $e->getHttpStatus() . "\n");
print('Type is:' . $err['type'] . "\n");
print('Code is:' . $err['code'] . "\n");
// param is '' in this case
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
} catch (Stripe_InvalidRequestError $e) {

// Invalid parameters were supplied to Stripe's API
} catch (Stripe_AuthenticationError $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
} catch (Stripe_ApiConnectionError $e) {
// Network communication with Stripe failed
} catch (Stripe_Error $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Stripe 动态付款 的相关文章

  • 如何使用 jest 模拟第三方库

    我正在开发一个node js应用程序使用nestjs我有一堂课叫LoggerService如下 export class LoggerService private logger Rollbar constructor this logge
  • Mysqli 更新抛出 Call to a member function bind_param() 错误[重复]

    这个问题在这里已经有答案了 我有一个 70 80 字段表单 需要插入到表中 因此我首先根据表单中的输入名称在数据库中创建了一个表 而不是手动创建一个巨大的插入语句 这是我使用的代码创建 更改表 function createTable ar
  • 使用 CryptoJS 更改密钥 [重复]

    这个问题在这里已经有答案了 我正在使用 CryptoJS 来加密和解密文本 在这里 我只是获取消息并显示加密和解密消息 我使用DES算法进行加密和解密 这是我的 HTML 文件
  • jquery window.open 在 ajax 成功中被阻止

    尝试在我的 ajax 成功调用中打开一个新的浏览器窗口 但是 它被阻止为弹出窗口 我做了一些搜索 发现用户事件需要绑定到 window open 才能避免这种情况发生 我还找到了这个解决方案 您可以在 ajax 之前打开一个空白窗口 然后在
  • 如何通过php获取网页的Open Graph协议?

    PHP 有一个简单的命令来获取网页的元标记 get meta tags 但这仅适用于具有名称属性的元标记 然而 开放图谱协议如今变得越来越流行 从网页获取 opg 值的最简单方法是什么 例如 我看到的基本方法是通过 cURL 获取页面并使用
  • javascript中按tab键时如何调用函数?

    我有一个这样的功能 function whenEmpty field if field value field style backgroundColor ffcccc alert Please fill the field field f
  • Ebay api GetSellerList,解析响应 XML

    我正在使用 eBay 交易 api 来获取当前列出的卖家股票 我正在使用 GetSellerList 调用 我在解析 xml 时遇到问题 然后将其插入到网站商店中 这是 xml 请求
  • 如何流式传输 OpenAI 的完成 API?

    我想流式传输结果通过 OpenAI 的 API 完成 https beta openai com docs api reference completions 该文档提到使用服务器发送的事件 https developer mozilla
  • Typeahead.js substringMatcher 函数说明

    我只是在做一些研究Typeahead js这是一个非常酷的图书馆 感谢文档 我已经成功地获得了一个基本的示例 该文档也非常好 但是我试图弄清楚以下代码块实际上在做什么 var substringMatcher function strs r
  • 从所有会话中注销

    我有一个注销选项 这是我的代码 session start session destroy setcookie key time 60 60 24 setcookie username time 60 60 24 我想添加另一个选项来注销所
  • JS用正则表达式替换数字

    我有元素的标识符 如下所示 form book 1 2 3 我想要的是用其他值替换该标识符中的第二个数字 我将函数 match 与以下正则表达式一起使用 var regexp d d d 但它返回我包含的数组 1 2 3 2 因此 当我尝试
  • IE11不监听MSFullscreenChange事件

    我正在尝试使用 Bigscreen js 在 IE11 中使用全屏 但 IE11 不监听 MS FullscreenChange 事件 document addEventListener MSFullscreenChange functio
  • 类型“typeof import("/home/kartik/Desktop/Ecommerce/ecommerce/node_modules/firebase/index")”上不存在属性“auth”。 TS(2339)

    我是 FireBase 的初学者 我正在尝试使用 Angular 通过 FireBase 实现 Google 登录 我在 auth 时收到上述错误 我特此附上login component ts和package json package l
  • 反向引用在 PHP 中不起作用

    最近我一直在研究 更多的是在实践中说实话 正则表达式 我注意到他的力量 我提出的这个要求 link https stackoverflow com questions 30380397 take the text up to a speci
  • 当用户单击链接时,如何记录 MixPanel 事件?

    当用户单击某种类型的链接时 我试图在 MixPanel 中记录一个事件 我正在使用 JQuery 不引人注意地完成此操作 据我所知 我需要添加一个回调函数 以便在记录事件后将用户带到 URL 这是我正在使用的代码 不幸的是
  • 如何使用 php 在 sql 查询中转义引号?

    我有一个疑问 sql SELECT CustomerID FROM tblCustomer WHERE EmailAddress addslashes POST username AND Password addslashes POST p
  • Stream_context_set_params 不适用于 ssh2.sftp 包装器

    我想使用类似的功能here http www php net manual en function stream notification callback php 请检查以下代码 function notify notification
  • 如果数字小于 10,则显示前导零 [重复]

    这个问题在这里已经有答案了 可能的重复 JavaScript 相当于 printf string format https stackoverflow com questions 610406 javascript equivalent t
  • 如何获取 UIWebView 中元素的位置?

    我在 iPad 程序中加载了 html 的 UIWebView 通过使用 webkit column width 我将 html 分为几列 padding 0px height 1024px webkit column gap 0px we
  • 使用 crypt() 加密

    我目前正在做一个非常安全的登录系统 但我是 crypt 函数的新手 需要一些快速帮助 我在注册过程中使用 crypt 加密密码字符串并将其保存到数据库中 但是 我如何在登录过程中解密密钥 或者我应该怎么做 或者是否可以对提交的密码字符串进行

随机推荐