Determine whether to send card field attributes by payment method type

This commit is contained in:
Rohan Mitchell
2014-06-04 16:55:27 +10:00
parent 6a8def3d76
commit fc3402bbd0
3 changed files with 9 additions and 4 deletions

View File

@@ -32,7 +32,7 @@ Darkswarm.factory 'Order', ($resource, order, $http, CheckoutFormState, flash, N
if CheckoutFormState.ship_address_same_as_billing
munged_order.ship_address_attributes = munged_order.bill_address_attributes
if @secrets.card_number?.length > 0
if @paymentMethod()?.method_type == 'gateway'
angular.extend munged_order.payments_attributes[0], {
source_attributes:
number: @secrets.card_number

View File

@@ -30,7 +30,8 @@ end
node :payment_methods do
Hash[current_order.available_payment_methods.collect {
|method| [method.id, {
name: method.name
name: method.name,
method_type: method.method_type
}]
}]
end

View File

@@ -26,6 +26,10 @@ describe 'Order service', ->
payment_methods:
99:
test: "foo"
method_type: "gateway"
123:
test: "bar"
method_type: "check"
angular.module('Darkswarm').value('order', orderData)
module 'Darkswarm'
@@ -60,7 +64,7 @@ describe 'Order service', ->
it 'Gets the current payment method', ->
expect(Order.paymentMethod()).toEqual null
Order.order.payment_method_id = 99
expect(Order.paymentMethod()).toEqual {test: "foo"}
expect(Order.paymentMethod()).toEqual {test: "foo", method_type: "gateway"}
it "Posts the Order to the server", ->
$httpBackend.expectPUT("/checkout", {order: Order.preprocess()}).respond 200, {path: "test"}
@@ -112,6 +116,6 @@ describe 'Order service', ->
expect(source_attributes.last_name).toBe Order.order.bill_address.lastname
it "does not create attributes for card fields when no card is supplied", ->
Order.secrets.card_number = ''
Order.order.payment_method_id = 123
source_attributes = Order.preprocess().payments_attributes[0].source_attributes
expect(source_attributes).not.toBeDefined()