Add credit card selection element to standing orders form

This commit is contained in:
Rob Harrington
2017-11-02 13:18:14 +11:00
parent 494f2f4821
commit 61b64a7516
6 changed files with 39 additions and 6 deletions

View File

@@ -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

View File

@@ -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)