mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Add credit card selection element to standing orders form
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
angular.module("admin.standingOrders").controller "DetailsController", ($scope, StatusMessage) ->
|
||||
$scope.cardRequired = false
|
||||
|
||||
$scope.registerNextCallback 'details', ->
|
||||
$scope.standing_order_form.$submitted = true
|
||||
if $scope.standing_order_details_form.$valid
|
||||
@@ -7,3 +9,13 @@ angular.module("admin.standingOrders").controller "DetailsController", ($scope,
|
||||
$scope.setView('address')
|
||||
else
|
||||
StatusMessage.display 'failure', t('admin.standing_orders.details.invalid_error')
|
||||
|
||||
$scope.$watch "standingOrder.payment_method_id", (newValue, oldValue) ->
|
||||
return if !newValue? || newValue == oldValue
|
||||
paymentMethod = ($scope.paymentMethods.filter (pm) -> pm.id == newValue)[0]
|
||||
return unless paymentMethod?
|
||||
if paymentMethod.type == "Spree::Gateway::StripeConnect"
|
||||
$scope.cardRequired = true
|
||||
else
|
||||
$scope.cardRequired = false
|
||||
$scope.standingOrder.credit_card_id = null
|
||||
|
||||
@@ -9,6 +9,7 @@ angular.module("admin.standingOrders").controller "StandingOrderController", ($s
|
||||
$scope.view = if $scope.standingOrder.id? then 'review' else 'details'
|
||||
$scope.nextCallbacks = {}
|
||||
$scope.backCallbacks = {}
|
||||
$scope.creditCards = []
|
||||
|
||||
successCallback = (response) ->
|
||||
StatusMessage.display 'success', 'Saved. Redirecting...'
|
||||
@@ -54,6 +55,8 @@ angular.module("admin.standingOrders").controller "StandingOrderController", ($s
|
||||
angular.extend($scope.standingOrder.bill_address, response.bill_address)
|
||||
angular.extend($scope.standingOrder.ship_address, response.ship_address)
|
||||
$scope.shipAddressFromBilling() unless response.ship_address.address1?
|
||||
$http.get("/admin/customers/#{newValue}/cards")
|
||||
.success (response) => $scope.creditCards = response.cards
|
||||
|
||||
$scope.shipAddressFromBilling = =>
|
||||
angular.extend($scope.standingOrder.ship_address, $scope.standingOrder.bill_address)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
= admin_inject_json_ams_array "admin.standingOrders", "shops", @shops, Api::Admin::IdNameSerializer if @shops
|
||||
= admin_inject_json_ams_array "admin.standingOrders", "customers", @customers, Api::Admin::IdEmailSerializer if @customers
|
||||
= admin_inject_json_ams_array "admin.standingOrders", "schedules", @schedules, Api::Admin::IdNameSerializer if @schedules
|
||||
= admin_inject_json_ams_array "admin.standingOrders", "paymentMethods", @payment_methods, Api::Admin::IdNameSerializer if @payment_methods
|
||||
= admin_inject_json_ams_array "admin.standingOrders", "paymentMethods", @payment_methods, Api::Admin::PaymentMethodSerializer if @payment_methods
|
||||
= admin_inject_json_ams_array "admin.standingOrders", "shippingMethods", @shipping_methods, Api::Admin::IdNameSerializer if @shipping_methods
|
||||
= admin_inject_json_ams_array "admin.standingOrders", "orderCycles", @order_cycles, Api::Admin::BasicOrderCycleSerializer if @order_cycles
|
||||
= admin_inject_available_countries(module: "admin.standingOrders")
|
||||
|
||||
@@ -14,13 +14,18 @@
|
||||
.error{ ng: { repeat: 'error in errors.schedule', show: 'standing_order_details_form.schedule_id.$pristine'} } {{ error }}
|
||||
|
||||
.row
|
||||
.seven.columns.alpha.field
|
||||
.columns.alpha.field{ ng: { class: '{four: cardRequired, seven: !cardRequired}' } }
|
||||
%label{ for: 'payment_method_id'}
|
||||
= t('admin.payment_method')
|
||||
%span.with-tip.icon-question-sign{ data: { powertip: "#{t('.allowed_payment_method_types_tip')}" } }
|
||||
%input.ofn-select2.fullwidth#payment_method_id{ name: 'payment_method_id', type: 'number', data: 'paymentMethods', required: true, placeholder: t('admin.choose'), ng: { model: 'standingOrder.payment_method_id' } }
|
||||
.error{ ng: { show: 'standing_order_form.$submitted && standing_order_details_form.payment_method_id.$error.required' } }= t(:error_required)
|
||||
.error{ ng: { repeat: 'error in errors.payment_method', show: 'standing_order_details_form.payment_method_id.$pristine' } } {{ error }}
|
||||
.three.columns.field{ ng: { show: 'cardRequired' } }
|
||||
%label{ for: 'credit_card_id'}= t('.credit_card')
|
||||
%input.ofn-select2.fullwidth#credit_card_id{ name: 'credit_card_id', type: 'number', data: 'creditCards', text: 'formatted', required: true, placeholder: t('admin.choose'), ng: { model: 'standingOrder.credit_card_id' } }
|
||||
.error{ ng: { show: 'standing_order_form.$submitted && standing_order_details_form.credit_card_id.$error.required' } }= t(:error_required)
|
||||
.error{ ng: { repeat: 'error in errors.credit_card', show: 'standing_order_details_form.credit_card_id.$pristine' } } {{ error }}
|
||||
.two.columns
|
||||
.seven.columns.omega.field
|
||||
%label{ for: 'shipping_method_id'}= t('admin.shipping_method')
|
||||
|
||||
@@ -850,6 +850,7 @@ en:
|
||||
details: Details
|
||||
invalid_error: Oops! Please fill in all of the required fields...
|
||||
allowed_payment_method_types_tip: Only Cash and Stripe payment methods may be used at the moment
|
||||
credit_card: Credit Card
|
||||
product_already_in_order: This product has already been added to the order. Please edit the quantity directly.
|
||||
orders:
|
||||
number: Number
|
||||
|
||||
@@ -122,7 +122,11 @@ feature 'Standing Orders' do
|
||||
|
||||
context 'creating a new standing order' do
|
||||
let(:address) { create(:address) }
|
||||
let!(:customer) { create(:customer, enterprise: shop, bill_address: address) }
|
||||
let!(:customer_user) { create(:user) }
|
||||
let!(:credit_card1) { create(:credit_card, user: customer_user, cc_type: 'visa', last_digits: 1111, month: 10, year: 2030) }
|
||||
let!(:credit_card2) { create(:credit_card, user: customer_user, cc_type: 'master', last_digits: 9999, month: 2, year: 2044) }
|
||||
let!(:credit_card3) { create(:credit_card, cc_type: 'visa', last_digits: 5555, month: 6, year: 2066) }
|
||||
let!(:customer) { create(:customer, enterprise: shop, bill_address: address, user: customer_user) }
|
||||
let!(:product1) { create(:product, supplier: shop) }
|
||||
let!(:product2) { create(:product, supplier: shop) }
|
||||
let!(:variant1) { create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: []) }
|
||||
@@ -131,7 +135,7 @@ feature 'Standing Orders' do
|
||||
let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
|
||||
let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
|
||||
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
|
||||
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
|
||||
let!(:payment_method) { create(:stripe_payment_method, name: 'Credit Card', distributors: [shop], preferred_enterprise_id: shop.id) }
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
|
||||
it "passes the smoke test" do
|
||||
@@ -145,11 +149,18 @@ feature 'Standing Orders' do
|
||||
select2_select payment_method.name, from: 'payment_method_id'
|
||||
select2_select shipping_method.name, from: 'shipping_method_id'
|
||||
|
||||
# No date filled out, so error returned
|
||||
# Credit card
|
||||
card1_option = "Visa x-1111 #{I18n.t(:card_expiry_abbreviation)}:10/2030"
|
||||
card2_option = "Master x-9999 #{I18n.t(:card_expiry_abbreviation)}:02/2044"
|
||||
card3_option = "Visa x-5555 #{I18n.t(:card_expiry_abbreviation)}:06/2066"
|
||||
expect(page).to have_select2 'credit_card_id', with_options: [card1_option, card2_option], without_options: [card3_option]
|
||||
|
||||
# No date or credit card filled out, so error returned
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'can\'t be blank'
|
||||
expect(page).to have_content 'can\'t be blank', count: 2
|
||||
expect(page).to have_content 'Oops! Please fill in all of the required fields...'
|
||||
fill_in 'begins_at', with: Date.today.strftime('%F')
|
||||
select2_select card2_option, from: 'credit_card_id'
|
||||
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'BILLING ADDRESS'
|
||||
@@ -245,6 +256,7 @@ feature 'Standing Orders' do
|
||||
expect(standing_order.shipping_method).to eq shipping_method
|
||||
expect(standing_order.bill_address.firstname).to eq 'Freda'
|
||||
expect(standing_order.ship_address.firstname).to eq 'Freda'
|
||||
expect(standing_order.credit_card_id).to eq credit_card2.id
|
||||
|
||||
# Standing Line Items are created
|
||||
expect(standing_order.standing_line_items.count).to eq 1
|
||||
|
||||
Reference in New Issue
Block a user