Skip to content

Commit

Permalink
Handle card brand string variations (#937)
Browse files Browse the repository at this point in the history
Allow parsing `AMERICAN_EXPRESS` and `DINERS_CLUB` strings as card brands.
  • Loading branch information
ramont-stripe authored Mar 31, 2022
1 parent aa80f8e commit b52831e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Stripe/STPPaymentMethodCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public class STPPaymentMethodCard: NSObject, STPAPIResponseDecodable {
let brand = string.lowercased()
if brand == "visa" {
return .visa
} else if brand == "amex" {
} else if brand == "amex" || brand == "american_express" {
return .amex
} else if brand == "mastercard" {
return .mastercard
} else if brand == "discover" {
return .discover
} else if brand == "jcb" {
return .JCB
} else if brand == "diners" {
} else if brand == "diners" || brand == "diners_club" {
return .dinersClub
} else if brand == "unionpay" {
return .unionPay
Expand Down
4 changes: 4 additions & 0 deletions Tests/Tests/STPPaymentMethodCardTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class STPPaymentMethodCardTest: XCTestCase {

XCTAssertEqual(STPPaymentMethodCard.brand(from: "amex"), .amex)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "AMEX"), .amex)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "american_express"), .amex)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "AMERICAN_EXPRESS"), .amex)

XCTAssertEqual(STPPaymentMethodCard.brand(from: "mastercard"), .mastercard)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "MASTERCARD"), .mastercard)
Expand All @@ -102,6 +104,8 @@ class STPPaymentMethodCardTest: XCTestCase {

XCTAssertEqual(STPPaymentMethodCard.brand(from: "diners"), .dinersClub)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "DINERS"), .dinersClub)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "diners_club"), .dinersClub)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "DINERS_CLUB"), .dinersClub)

XCTAssertEqual(STPPaymentMethodCard.brand(from: "unionpay"), .unionPay)
XCTAssertEqual(STPPaymentMethodCard.brand(from: "UNIONPAY"), .unionPay)
Expand Down

0 comments on commit b52831e

Please sign in to comment.