- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前正在尝试在我的 angular4 Nodejs 应用程序中实现 stripe,但是当我尝试通过处理与 stripe 相关的请求的服务将卡 token 发送到我的服务器时,我有点卡住了。这是我得到的代码:
stripe.component.html:
<form role="form" id="payment-form">
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
<button type="submit" (click)="addCard()">Submit Payment</button>
</form>
stripe.component.ts:
import {Component, OnInit} from "@angular/core";
import {WindowRef} from "../social/windowRef";
import {StripeService} from "./stripe.service";
@Component({
selector: "app-stripe",
templateUrl: './stripe.component.html',
styleUrls: ['./stripe.component.css']
})
export class StripeComponent implements OnInit {
elements: any;
stripe: any;
style: any;
card: any;
constructor(private stripeService: StripeService){}
ngOnInit() {
this.initCardElement();
}
initCardElement(){
this.stripe = WindowRef.get().Stripe("my-key");
this.elements = this.stripe.elements();
this.style =
{
base: {
color: '#32325d',
lineHeight: '24px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
this.card = this.elements.create('card', {style: this.style});
this.card.mount('#card-element');
}
addCard() {
this.stripe.createToken(this.card)
.then(function (result) {
if (result.error) {
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
console.log(result.token);
this.stripeService.addCard(result.token)
.subscribe((response: Response) => {
console.log(response);
}
);
}
});
}
}
我设法获取了 stripe 的卡 token ,但是当我尝试调用我的 stripeService 时,出现了此错误:
Error: Uncaught (in promise): TypeError: Cannot read property 'stripeService' of undefined
我知道 this.stripeService
未在此处定义,但我不明白如何解决此问题。
祝你有美好的一天:)
最佳答案
如果您想使用外部 this
,请使用箭头函数。使用 function
声明的函数会创建一个新的 this
,但此处未定义。
运行此示例以查看发生了什么:
class X {
constructor(x) {
this.x = x;
}
a() {
(function () {
console.log(this.x);
})();
}
b() {
(() => {
console.log(this.x);
})();
}
}
let x = new X(10);
x.b();
x.a();
此处,b()
方法内的函数正确使用外部 this
,但 a()
方法有一个创建自己的 this
的函数,该函数未定义并导致错误:
TypeError: Cannot read property 'x' of undefined
在您的示例中,您可以更改此设置:
addCard() {
this.stripe.createToken(this.card)
.then(function (result) {
if (result.error) {
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
console.log(result.token);
this.stripeService.addCard(result.token)
.subscribe((response: Response) => {
console.log(response);
}
);
}
});
}
对此:
addCard() {
this.stripe.createToken(this.card)
.then((result) => {
if (result.error) {
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
console.log(result.token);
this.stripeService.addCard(result.token)
.subscribe((response: Response) => {
console.log(response);
}
);
}
});
}
(未测试)
关于node.js - Stripe Angular 错误: Uncaught (in promise): TypeError: Cannot read property 'stripeService' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45147544/
我可以在不使用收款人信用卡号的情况下将资金从我的 Stripe 账户发送到另一个 Stripe 账户吗?在我的网站中,我希望管理员将资金从他的帐户转移到用户的条纹帐户(而不是用户的银行帐户)。用户的
我曾经有 Angular Stripe Checkout 表单,我正在尝试将表单更新为新的 Stripe Card Elements这是最近推出的。 删除表单输入字段并将其替换为条纹卡片元素后,我的表
我的目标是为产品创建一个简单的支付页面。 在官方文档中,它说在服务器端需要生成 token 才能创建交易,使用: stripe.paymentIntents.create({ amount: re
我是 strip 的新手,打算使用 strip token /收费 api,但 strip 文档说 paymentIntent api 是新的方法。我可以使用任何人吗或 PaymentIntent 是
我正在开发一个项目,我们正在为 Node 使用 Stripe 库。我们还想在这个项目上使用 TypeScript。 我发现 Stripe 没有提供官方 TypeScript 定义,但我找到了一些社区定
通常在使用 stripe 时我可以创建产品并添加税率、运费。付款后我可以创建发票。我想在使用连接帐户时做同样的事情。在我的应用程序中,我希望用户创建商店,并且该商店的产品将保存到他们连接的 Strip
假设我们已经设置了一个 Stripe 订阅计划。即 30 美元/月。 (注意:账单/账户信息存储在 Stripe 上。) 假设我们想为客户提供提前购买一年服务的选项,如果他们这样做,他们只需支付 25
我们知道 Stripe 支持多张信用卡。一个是 default_card。关于这张 Stripe 多张卡片,我需要知道一些答案。 假设我想向我的客户收费,他的 Stripe 个人资料中有 3 张信用卡
有没有办法根据为特定客户生成的最后一张发票过滤发票结果? 穿过 Stripe documentation我可以看到有可能获得即将到来的发票,但我找不到获得最后生成的发票的方法。 最佳答案 如果您使用
我正在使用 Stripe 为客户订阅月度计划。中途客户可能会减少计划数量。所以,在即将开出的发票有时会是负数。 带有负金额的发票行是否意味着客户将这些金额退还到他们的卡中? 谢谢 最佳答案 是的,负发
我正在使用定期计划和电子邮件地址在 Stripe(使用测试模式)中创建客户。到目前为止,一切都按我的预期工作:当客户创建并注册到定期计划时,他们会自动在计划的第一期收费。我所拥有的几乎是逐字逐句wha
我正在尝试使用 Stripe checkout.js 订阅,然后使用 PHP 订阅客户。我的问题是获取他们的电子邮件地址。在文档中找不到任何有用的东西。 文档在这里:https://stripe.co
我在两部分付款过程中使用 Stripe。 IE。 使用 capture = false 对调用 Charge 对象的卡进行预授权 做一些数据库工作 使用电荷捕获为卡充电 如果第 2 步失败(即数据库工
我们使用 Stripe 作为支付网关,我们有一个年度计划,即该计划的计费周期为 1 年。 在计费周期内,用户可以更新选择更多席位,这将导致增加订阅计划的数量。 Subscription subscri
我正在使用 PHP Stripe Payment 表单来收款。付款似乎通过 OK 并在成功完成后将用户带到确认页面。我处于测试模式,能够看到显示在仪表板“付款”部分的付款。但是,当我单击仪表板的“主页
我正在构建一个市场应用程序。我正在使用 Stripe 接受买家付款并将百分比转移给卖家。但是,stripe 只能让您从 Stripe 余额中转移。因此,如果我接受需要 2 个工作日才能显示在我的 st
正如我们所知,Stripe 每张信用卡收费 2.9% + 30 美分。因此,对于每 1 美元的交易,Stripe 大约需要 33 美分。有没有办法批量处理多个 1 美元的交易(由同一客户)并完全收费?
我有一个关于 Stripe 的订阅计划,并将其用于按座位定价。 具体用例是: 客户之前已付款,因此数据库中的客户 ID 和订阅 ID 他们在一个月内删除了所有用户 下个月他们又添加了一个用户 我希望结
在Stripe API文档中,它们显示您可以在客户上应用优惠券。 cust = Stripe::Customer.retrieve("cus_asdasdad") cust.coupon = "COU
我在订阅中添加发票项目时遇到问题,目前无法正常工作。 我已经在 strip 上创建了一个发票项目,并且希望该发票项目包含在定期付款中 这是我的代码,它在第一个发票上添加了一个发票项目,但在下一个发票上
我是一名优秀的程序员,十分优秀!