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
}
);