krishamoud / meteor-accounts-stripe

stripe connect package
10 stars 11 forks source link

Should work decently #7

Open dbismut opened 8 years ago

dbismut commented 8 years ago

Hi - I’ve made several changes to the project, mimicking the official Meteor Facebook package while trying to be relevant to the Stripe OAuth and API.

To be used, you should configure your Stripe App as below server-side:

  Meteor.startup(function() {
    Accounts.loginServiceConfiguration.upsert({
      service: 'stripe'
        }, {
        $set: {
          service: 'stripe',
          appId: YOUR_STRIPE_CLIENT_ID,
          secret: YOUR_STRIPE_SECRET_KEY,
          loginStyle: 'redirect',
          scope: 'read_write' //or read_only
        }
      });
    }
  );

I prefer the loginStyle to be redirect but note that in that case the callback from loginWithStripe won’t work (this is the expected behavior).

Therefore, you can call Meteor.loginWithStripe simply as Meteor.loginWithStripe().

shacks commented 8 years ago

Hey, I was wndering if you could help me out. How do I go about adding the stripe credentials to an already registered account. For example if I am already logged in with facebook, I want my stripe creditials to be stored into my facebook user document instead of a new document being created?

dbismut commented 8 years ago

Hi @shacks, I haven't been testing this for a long time, but I know there is this package that is supposed to link an account instead of creating a new user on login.

On my end, I was using:

if (Meteor.isServer) {
  var orig_updateOrCreateUserFromExternalService = Accounts.updateOrCreateUserFromExternalService;
  Accounts.updateOrCreateUserFromExternalService = function (serviceName, serviceData, options) {
    var loggedInUser = Meteor.user();
    if (loggedInUser && typeof (loggedInUser.services[serviceName]) === 'undefined') {
      var setAttr = {};
      setAttr['services.' + serviceName] = serviceData;
      Meteor.users.update(loggedInUser._id, {
        $set: setAttr
      });
    }
    else {
      throw new Error("User does not exist, and therefore can't connect account");
    }
    return orig_updateOrCreateUserFromExternalService.apply(this, arguments);
  };
}
else {
  if (Package['accounts-base']) {
    Meteor.startup(function() {
      Accounts._loginButtons.getLoginServices = function () {
        return this.hasPasswordService() ? [{
          name: 'password'
      }] : [];
      }
    });
  }
}

I can't remember where I stole the code from, but essentially it patches Meteor's login system with a method that links an account when a user exists.

shacks commented 8 years ago

@dbismut Thanks man, not sure exactly how your code works, But I tried the package you mentioned. I just added a stripe.js file into the core services folder and it works like a charm!!!