0

I'm trying to remove customer's credit card information with a wrapAsync method. I've managed to successfully create a customer with saimeunt's awesome answer, but for some reason I can't get it to work with Stripe.customers.deleteCard.

Here's how client side looks like:

<button type="button" class="btn btn-danger" id="removeCard">
    Remove Card
</button>

Template.payments.events({
'click #removeCard': function(e) {
    e.preventDefault();

    Meteor.call('deleteStripeCard', function(error, response) {
        if (error) {
            toastr.error('Failed to remove card.', 'Error');
            console.log(error);
        } else {
            toastr.success('Credit card removed successfully', 'Success');
        }
    });
}
});

And this is on the server:

Meteor.methods({
'deleteStripeCard': function() {
var customerStripeId = Meteor.user().stripeId;
var customerCardId = Meteor.user().cardId;

var stripeCustomersDeleteCard = 
Meteor.wrapAsync(Stripe.customers.deleteCard, Stripe.customers);

var result = stripeCustomersDeleteCard({
  customerId: customerStripeId,
  cardId: customerCardId
});

console.log(result);
});

I think the problem is with the Meteor.wrapAsync context (Stripe.customers), but I'm having hard time wrapping my head around it. I've tried changing the context to point to .sources, .customer.sources and many others but with no luck. I doubt that the problem is elsewhere though, since the asynchronous code from Stripe (see below) does delete the card.

stripe.customers.deleteCard(
"cus_7x...",
"card_17q...",
function(err, confirmation) {
// asynchronously called
}
);
Community
  • 1
  • 1
JP_CO
  • 1
  • 1
  • It's my first question on stackoverflow so any feedback on how to pose the question would be more than welcome! – JP_CO Sep 13 '15 at 18:24
  • I'd strongly recommend a package like `copleykj:stripe-sync`. It wraps it for you and exposes all the necessary functions. – ffxsam Sep 14 '15 at 00:21
  • Thanks for the suggestion @ffxsam! I took a look at the package and might end up installing it. I'm still struggling to understand what is the context in the wrapAsync method above though. I feel like it would be an important concept to grasp and not just for Stripe handling. – JP_CO Sep 14 '15 at 14:36

0 Answers0