Я пытаюсь предложить пользователю 7-дневную бесплатную пробную версию, прежде чем они будут заряжены. Я положил в план пробный период 7 дней. Тем не менее, он взимает плату с пользователя мгновенно.
Я также пытался передать аргумент, подобный этому
const stripe = require("stripe")("sk_test_key");
if (planType === "monthly") {
stripe.subscriptions.create(
{
customer: customer,
items: [
{
plan: "plan...."
}
],
coupon: coupon
trial_end : 1579313395
},
function(err, subscription) {
addDataToUserProfile(uid, "subscription", subscription);
}
);
} else if (planType === "1year") {
stripe.subscriptions.create(
{
customer: customer,
items: [
{
plan: "plan......."
}
],
coupon: coupon
},
function(err, subscription) {
addDataToUserProfile(uid, "subscription", subscription);
}
);
} else {
console.log("invalid plan type selected");
}
};
Это приводит к ошибке платежа. Тогда я называю это в этой функции.
exports.addStripeID = functions.https.onCall((data, context) => {
const stripe = require("stripe")("sk_test_key");
const uid = data.uid;
const source = data.source;
const email = data.email;
const planType = data.planType;
const coupon = data.coupon;
return stripe.customers
.create({
source: source,
email: email
})
.then(
customer => {
addCustomerToPlan(customer.id, uid, planType, coupon);
addData(uid, "stripeID", customer.id);
return { success: true };
},
err => {
console.log("the error", err);
return { error: err, message: "there was an error", success: false };
}
)
});
Вот как я это называю в firebase.
doAddStripeID(source, email, uid, planType, coupon) {
console.log("do add stripe ID local function called");
//change to this.functions
var addData = app.functions().httpsCallable("addStripeID");
addData({ source: source, email: email, uid: uid, planType: planType, coupon: coupon})
.then(function (result) {
console.log("add stripe result is ", result);
// this.doAddDataToUser(uid, result.key, result.value)
if (result.data.success) {
console.log("it works");
//this can probably be fixed with a reload instead of a interval
setInterval(() => { window.location.assign("/payment-success") }, 3000);
} else {
console.log("nope");
setInterval(() => { window.location.assign("/payment-failure") }, 3000);
}
})
.catch(err => {
console.log(err.code);
});
}