Skip to content

Instantly share code, notes, and snippets.

@yonjah
Last active April 18, 2018 06:53
Show Gist options
  • Select an option

  • Save yonjah/8b599a13f8c7555b0ae6ac6ec1ae3dd9 to your computer and use it in GitHub Desktop.

Select an option

Save yonjah/8b599a13f8c7555b0ae6ac6ec1ae3dd9 to your computer and use it in GitHub Desktop.

Revisions

  1. yonjah revised this gist Apr 18, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion native-middleware.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ async function chargeCreate ({ amount, source, description, currency }) {
    myTraceService.log(`New charge ${charge.amount}`);
    return charge;
    } catch (e) {
    // do some thing with the error if you want to
    // do something with the error if you want to
    throw e;
    }
    }
  2. yonjah revised this gist Apr 18, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion native-middleware.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ async function chargeCreate ({ amount, source, description, currency }) {
    //do some stuff before the function
    await someService.doAsyncStuff(amount, currency, description);
    try {
    const charge = await stripe.charges.create({ amount, source, description, currency });
    const charge = await stripe.charges.create.apply(stripe.charges, arguments);
    //do some stuff after the function
    myTraceService.log(`New charge ${charge.amount}`);
    return charge;
  3. yonjah created this gist Apr 18, 2018.
    30 changes: 30 additions & 0 deletions native-middleware.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    async function chargeCreate ({ amount, source, description, currency }) {
    //do some stuff before the function
    await someService.doAsyncStuff(amount, currency, description);
    try {
    const charge = await stripe.charges.create({ amount, source, description, currency });
    //do some stuff after the function
    myTraceService.log(`New charge ${charge.amount}`);
    return charge;
    } catch (e) {
    // do some thing with the error if you want to
    throw e;
    }
    }

    // No changes on the processPayement
    async function processPayement (amount, source, description) {
    let charge;
    try {
    charge = await chargeCreate({
    amount,
    source,
    description,
    currency: "usd"
    });
    } catch (e) {
    // Error handling
    }

    // ...
    }