Stripe Angular Ionic Application - Making Payment

I am creating a Stripe payment system , and I am having difficulty making this integrated functional code work. The code has been pulled out of here . What I'm trying to do is create a database link to a specific user identifier (uid) of the user, as it createStripeChargeexpects something to write eventhappen /stripe_customers/XCXaweADowefj/charges/QC123XYZ. I am not sure, but perhaps my problem is that I am referring incorrectly to the client. If you have any ideas or feedback on how I can perform this function correctly, I am very grateful for that!

Trigger (this causes the cloud function to work):

payByStripe(amount,email,userId, token): firebase.database.Reference {
  return firebase.database().ref(`/stripe_customers/${userId}/charges/`).push({
    amount:amount,
    email:email,
    token:token
  });    
}

Cloud function:

exports.createStripeCharge = functions.database.ref('/stripe_customers/{userId}/charges/{id}').onWrite(event => {
  const val = event.data.val();
  if (val === null || val.id || val.error) return null;
  return admin.database().ref(`/stripe_customers/${event.params.userId}/customer_id`).once('value').then(snapshot => {
    return snapshot.val();
  }).then(customer => {
    const amount = val.amount;
    const idempotency_key = event.params.id;
    let charge = {amount, currency, customer};
    if (val.source !== null) charge.source = val.source;
    return stripe.charges.create(charge, {idempotency_key});
  }).then(response => {
      return event.data.adminRef.set(response);
    }, error => {
      return event.data.adminRef.child('error').set(userFacingMessage(error)).then(() => {
        return reportError(error, {user: event.params.userId});
      });
    }
  );
});

, , "You have passed a blank string for 'customer'. You should remove the 'customer' parameter from your request or supply a non-blank value."

- , . :

firebase.database().ref(`/stripe_customers/${userId}/charges/`).push({
  amount:amount,
  email:email,
  token:token,
  customer: userId
});    

& &

firebase.database().ref(`/stripe_customers/${userId}/charges/`).push({
  amount:amount,
  email:email,
  token:token,
  customer_id:{
    customer: userId
  }
});    

" " ". " " ."

+4

Source: https://habr.com/ru/post/1692281/


All Articles