Refactor formatting of credit card brand names and reformat automatically when saving

This little bit of "translation" between what we might receive as input and what ActiveMerchant requires is important, but currently the responsibility for this job is spread all over the code base. It can now just live in the CreditCard model (in one place) and doesn't need to be duplicated anywhere else (like several different places in frontend Javascript!)
This commit is contained in:
Matt-Yorkley
2021-12-02 14:43:12 +00:00
parent f56dc2e284
commit 4cdb892c75
5 changed files with 72 additions and 97 deletions

View File

@@ -34,7 +34,7 @@ describe 'StripeElements Service', ->
StripeElements.requestToken(secrets, submit)
$rootScope.$digest() # required for #then to by called
expect(secrets.token).toEqual "token"
expect(secrets.cc_type).toEqual "master"
expect(secrets.cc_type).toEqual "MasterCard"
expect(submit).toHaveBeenCalled()
describe "with unsatifactory data", ->
@@ -52,19 +52,3 @@ describe 'StripeElements Service', ->
expect(Loading.clear).toHaveBeenCalled()
expect(RailsFlashLoader.loadFlash).toHaveBeenCalledWith({error: "Error: There was a problem"})
expect(Bugsnag.notify).toHaveBeenCalled()
describe 'mapTokenApiCardBrand', ->
it "maps the brand returned by Stripe's tokenAPI to that required by activemerchant", ->
expect(StripeElements.mapTokenApiCardBrand('MasterCard')).toEqual "master"
expect(StripeElements.mapTokenApiCardBrand('Visa')).toEqual "visa"
expect(StripeElements.mapTokenApiCardBrand('American Express')).toEqual "american_express"
expect(StripeElements.mapTokenApiCardBrand('Discover')).toEqual "discover"
expect(StripeElements.mapTokenApiCardBrand('JCB')).toEqual "jcb"
expect(StripeElements.mapTokenApiCardBrand('Diners Club')).toEqual "diners_club"
describe 'mapPaymentMethodsApiCardBrand', ->
it "maps the brand returned by Stripe's paymentMethodsAPI to that required by activemerchant", ->
expect(StripeElements.mapPaymentMethodsApiCardBrand('mastercard')).toEqual "master"
expect(StripeElements.mapPaymentMethodsApiCardBrand('amex')).toEqual "american_express"
expect(StripeElements.mapPaymentMethodsApiCardBrand('diners')).toEqual "diners_club"
expect(StripeElements.mapPaymentMethodsApiCardBrand('visa')).toEqual "visa"