Angular canMakePayment()在LOCALHOST中始终返回null
我试图显示“支付”按钮,但Angular canMakePayment()在LOCALHOST中始终返回null,angular,stripe-payments,Angular,Stripe Payments,我试图显示“支付”按钮,但paymentRequest.canMakePayment()始终返回空值。我在chrome上的LOCALHOST(73.0.3683.75版)上执行此代码,并且该卡也保存在chrome上 import { Component, OnInit } from '@angular/core'; declare let Stripe; @Component({ selector: 'hts-card-details', templateUrl: './card-
paymentRequest.canMakePayment()
始终返回空值。我在chrome上的LOCALHOST(73.0.3683.75版)上执行此代码,并且该卡也保存在chrome上
import { Component, OnInit } from '@angular/core';
declare let Stripe;
@Component({
selector: 'hts-card-details',
templateUrl: './card-details.component.html'
})
export class demo implements OnInit {
card: any;
stripe_value: any;
elements: any;
paymentRequest: any;
prButton: any;
constructor() { }
ngOnInit() {
this.displayStripeCard('pk_test_mMvKPSkT746S4xp6FMhMOk3W'); // for testing
}
displayStripeCard(stripeKey) {
this.stripe_value = Stripe(stripeKey);
this.elements = this.stripe_value.elements();
// Custom styling can be passed to options when creating an Element.
this.card = this.elements.create('card', {style});
// Mount the Card Element on the page.
this.card.mount('#card-element');
// Handle real-time validation errors from the card Element.
this.card.addEventListener('change', function(event) {
const displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// create payment method
this.paymentRequest = this.stripe_value.paymentRequest({
country: 'US',
currency: 'usd',
total: {
label: 'Demo total',
amount: 200,
},
requestPayerName: true,
requestPayerEmail: true,
});
this.prButton = this.elements.create('paymentRequestButton', {
paymentRequest: this.paymentRequest,
});
this.mountButton();
}
async mountButton() {
await this.paymentRequest.canMakePayment().then(function (result) {
debugger;
console.log(result); // returns null
});
}
}
即使在本地环境中也必须使用https。请参阅“先决条件”下的更多内容:您的方法canMakePayment()在哪里?它在mountButton()函数中