【发布时间】:2016-08-16 23:21:35
【问题描述】:
我正在使用 ember.js(2.0)、braintree-web 进行支付。
用户可以使用如下图所示的 Drop-in UI 添加他们的卡信息。
用户可以在如下图所示的帐户页面中查看他们的卡列表。
如果用户想删除他们的卡片列表,可以通过点击删除列表。我能怎么做?我想我可以在收到令牌的 deletePaymentMethod 中删除。
这是我的 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);
});
}
}
});
【问题讨论】: