mardi 16 août 2016

how can I delete added card list with braintree-web on ember.js

I am using ember.js(2.0), braintree-web for payment.

Users can add their card information using Drop-in UI like below image.

users card list

And users can see their card list in an account page like below image.

added card list

If a user wants to delete their card lists, the lists can be deleted by click. How can I do? I think I can delete in deletePaymentMethod with token received. But I don't know how I do. Please help me. thank you.

  1. here is my payment-selector.js
import Ember from 'ember';

export default Ember.Component.extend({

  ajax: Ember.inject.service(),
  session: Ember.inject.service(),

  createNewPaymentMethod: false,

  selectPaymentMethods: Ember.computed(function() {
    let array = this.get('paymentMethodsArray');
    array.pushObject({id:'newPaymentMethod',title:'Add new payment method'});
    return array;
  }),

  paymentMethodsArray:  Ember.computed.map('paymentMethods', function(item, index){
    return {id: item.get('token'), title: `${item.get('bin')}...${item.get('last4')}`};
  }),

  actions: {
    updatePaymentMethod: function(selection) {
      Ember.Logger.debug(selection);
      if (selection.id == 'newPaymentMethod') {
        this.set('createNewPaymentMethod', true);
      } else {
        this.set('createNewPaymentMethod', false);
        this.sendAction('onPaymentMethodSelection', {token:selection.id});
      }
    },

    processBraintreeNonce: function(nonce) {
      Ember.Logger.debug(nonce);
      const self = this;
      const authenticated = this.get('session.data.authenticated');
      this.get('ajax').request(`account/${authenticated.account.id}/payment_methods`,{
        method: 'POST',
        data: {
          nonce: nonce
        }
      }).then(function(response){
        Ember.Logger.debug(response);
        self.sendAction('onPaymentMethodSelection', response.data);
        self.set('hideBrainTreeSubmit', true);
      }).catch(function(reason){
        self.set('hideBrainTreeSubmit', false);
        Ember.Logger.debug(reason);
      });
    }
  }
});



Aucun commentaire:

Enregistrer un commentaire