mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-02 07:39:26 +00:00
Add google pay button
This commit is contained in:
parent
8dfdca567d
commit
fae369cff7
assets/javascripts/discourse
components
controllers
templates
@ -0,0 +1,42 @@
|
|||||||
|
import Component from "@ember/component";
|
||||||
|
|
||||||
|
export default Component.extend({
|
||||||
|
didInsertElement() {
|
||||||
|
this._super(...arguments);
|
||||||
|
this.paymentRequest.canMakePayment().then((result)=> {
|
||||||
|
if(result) {
|
||||||
|
// mount the element
|
||||||
|
this.buttonElement.mount("#payment-request-button");
|
||||||
|
} else {
|
||||||
|
//hide the button
|
||||||
|
document.getElementById("payment-request-button").style.display = "none";
|
||||||
|
console.log("GooglePay is unvailable")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.setbuttonElementStyles();
|
||||||
|
this.paymentRequest.on("paymentMethod", async (e) => {
|
||||||
|
// create a payment intent on the server
|
||||||
|
// confirm the payment on the client
|
||||||
|
console.log(e);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setbuttonElementStyles() {
|
||||||
|
const root = document.querySelector(":root");
|
||||||
|
const computedStyle = getComputedStyle(root);
|
||||||
|
const primaryColor = computedStyle.getPropertyValue("--primary");
|
||||||
|
const placeholderColor =
|
||||||
|
computedStyle.getPropertyValue("--secondary-medium");
|
||||||
|
this.buttonElement.update({
|
||||||
|
style: {
|
||||||
|
base: {
|
||||||
|
color: primaryColor,
|
||||||
|
"::placeholder": {
|
||||||
|
color: placeholderColor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
didDestroyElement() {},
|
||||||
|
});
|
@ -21,6 +21,28 @@ export default Controller.extend({
|
|||||||
const elements = this.get("stripe").elements();
|
const elements = this.get("stripe").elements();
|
||||||
|
|
||||||
this.set("cardElement", elements.create("card", { hidePostalCode: true }));
|
this.set("cardElement", elements.create("card", { hidePostalCode: true }));
|
||||||
|
|
||||||
|
this.initButtonPay();
|
||||||
|
},
|
||||||
|
|
||||||
|
initButtonPay() {
|
||||||
|
const elements = this.get("stripe").elements();
|
||||||
|
const paymentRequest = this.get("stripe").paymentRequest({
|
||||||
|
currency: "usd",
|
||||||
|
country: "US",
|
||||||
|
requestPayerName: true,
|
||||||
|
requestPayerEmail: true,
|
||||||
|
total: {
|
||||||
|
label: "test payment apple",
|
||||||
|
amount: 99,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.set("buttonElement",
|
||||||
|
elements.create('paymentRequestButton', {
|
||||||
|
paymentRequest: paymentRequest,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
this.set("paymentRequest", paymentRequest);
|
||||||
},
|
},
|
||||||
|
|
||||||
alert(path) {
|
alert(path) {
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
<div id="payment-request-button"></div>
|
@ -24,6 +24,7 @@
|
|||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
{{subscribe-card cardElement=cardElement}}
|
{{subscribe-card cardElement=cardElement}}
|
||||||
|
{{subscribe-google-pay buttonElement=buttonElement paymentRequest=paymentRequest}}
|
||||||
|
|
||||||
{{#if loading}}
|
{{#if loading}}
|
||||||
{{loading-spinner}}
|
{{loading-spinner}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user