简体   繁体   中英

Meteor issue Stripe refund (mrgalaxy:stripe)

How to issue refunds with mrgalaxy:stripe?

Stripe.refunds.create(refund, function(err, receipt) {
  ...
});

resulted in Exception while simulating the effect of invoking 'rejectUserFromProject' TypeError: Cannot read property 'create' of undefined(…) TypeError: Cannot read property 'create' of undefined

I use StripeCheckout for charges, and couldn't find if there was a refund method for it:

StripeCheckout.open({
    key: _key,
    amount: fee * 100,
    currency: 'usd',
    name: 'name',
    description: 'description',
    panelLabel: 'label',
    token: function(receipt) {
      console.info(receipt);
  });

Checkout is a UX/UI module for cc transactions, and handling is dependent on the server side library or call, where authentication includes the server secret (ie Checkout utilizes public key).

mrgalaxy:meteor includes the Node.js Stripe API, however, I didn't spend my time well.. the better solution is to use the API from there.

The hack for now was to import the Stripe npm package, and using the meteorhacks:npm package .

Created a package.json file with the Stripe dep, and code ended up looking:

if (Meteor.isServer) {
  var stripe = Meteor.npmRequire("stripe")(
    Meteor.settings.private.testSecretKey
  );

  stripe.refunds.create(returnObj, function(err, refund) {
    // asynchronously called
    if (err) {
      // handle
    };
  });
};

Also, since the code is executing in a callback there would be issues to use Meteor's or other's promise-based methods, maybe assign in the parent scope though i didn't try that, so there's a need to encapsulate with Fiber as-is:

stripe.refunds.create({
  // ...
}, Meteor.bindEnvironment(function (err, refund) {
  // ...
}));

Finally, Meteor 1.3 supports npm integration so with that you wouldn't have to use anything unfamiliar:

if (Meteor.isServer) {
  var stripe = require("stripe")(
    Meteor.settings.private.testSecretKey
  );

  stripe.refunds.create(returnObj, function(err, refund) {
    // asynchronously called
    if (err) {
      // handle
    };
  });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM