mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-12 23:27:48 +00:00
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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user