mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Configure StripeElements service to map cc_type to that used by activemerchant
This commit is contained in:
@@ -23,19 +23,20 @@ Darkswarm.factory 'StripeElements', ($rootScope, Loading, RailsFlashLoader) ->
|
||||
secrets.card = response.token.card
|
||||
submit()
|
||||
|
||||
# Maps the brand returned by Stripe to that required by activemerchant
|
||||
mapCC: (ccType) ->
|
||||
if ccType == 'MasterCard'
|
||||
return 'mastercard'
|
||||
return 'master'
|
||||
else if ccType == 'Visa'
|
||||
return 'visa'
|
||||
else if ccType == 'American Express'
|
||||
return 'amex'
|
||||
return 'american_express'
|
||||
else if ccType == 'Discover'
|
||||
return 'discover'
|
||||
else if ccType == 'Diners Club'
|
||||
return 'dinersclub'
|
||||
else if ccType == 'JCB'
|
||||
return 'jcb'
|
||||
else if ccType == 'Diners Club'
|
||||
return 'diners_club'
|
||||
return
|
||||
|
||||
# It doesn't matter if any of these are nil, all are optional.
|
||||
|
||||
@@ -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 "mastercard"
|
||||
expect(secrets.cc_type).toEqual "master"
|
||||
expect(submit).toHaveBeenCalled()
|
||||
|
||||
describe "with unsatifactory data", ->
|
||||
@@ -51,3 +51,12 @@ describe 'StripeElements Service', ->
|
||||
expect(submit).not.toHaveBeenCalled()
|
||||
expect(Loading.clear).toHaveBeenCalled()
|
||||
expect(RailsFlashLoader.loadFlash).toHaveBeenCalledWith({error: "Error: There was a problem"})
|
||||
|
||||
describe 'mapCC', ->
|
||||
it "maps the brand returned by Stripe to that required by activemerchant", ->
|
||||
expect(StripeElements.mapCC('MasterCard')).toEqual "master"
|
||||
expect(StripeElements.mapCC('Visa')).toEqual "visa"
|
||||
expect(StripeElements.mapCC('American Express')).toEqual "american_express"
|
||||
expect(StripeElements.mapCC('Discover')).toEqual "discover"
|
||||
expect(StripeElements.mapCC('JCB')).toEqual "jcb"
|
||||
expect(StripeElements.mapCC('Diners Club')).toEqual "diners_club"
|
||||
|
||||
Reference in New Issue
Block a user