Skip to content

Commit

Permalink
Merge pull request #147 from stripe/feat/create-card-with-token
Browse files Browse the repository at this point in the history
Feat/create card with token
  • Loading branch information
thorsten-stripe authored Apr 5, 2021
2 parents 8dc1eea + 407fd89 commit 9238180
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
16 changes: 10 additions & 6 deletions android/src/main/java/com/reactnativestripesdk/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,16 @@ internal fun mapToPaymentMethodCreateParams(cardData: ReadableMap): PaymentMetho
}

internal fun mapToCard(card: ReadableMap): PaymentMethodCreateParams.Card {
return PaymentMethodCreateParams.Card.Builder()
.setCvc(card.getString("cvc"))
.setExpiryMonth(card.getInt("expiryMonth"))
.setExpiryYear(card.getInt("expiryYear"))
.setNumber(card.getString("number").orEmpty())
.build()
if (card.hasKey("token")) {
return PaymentMethodCreateParams.Card.create(card.getString("token")!!)
} else {
return PaymentMethodCreateParams.Card.Builder()
.setCvc(card.getString("cvc"))
.setExpiryMonth(card.getInt("expiryMonth"))
.setExpiryYear(card.getInt("expiryYear"))
.setNumber(card.getString("number").orEmpty())
.build()
}
}

fun getValOr(map: ReadableMap, key: String, default: String? = ""): String? {
Expand Down
5 changes: 5 additions & 0 deletions ios/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ class Mappers {
}

class func mapToPaymentMethodCardParams(params: NSDictionary) -> STPPaymentMethodCardParams {
if let token = params["token"] {
let methodParams = STPPaymentMethodCardParams()
methodParams.token = RCTConvert.nsString(token)
return methodParams
}
let cardSourceParams = STPCardParams()
cardSourceParams.number = RCTConvert.nsString(params["number"])
cardSourceParams.cvc = RCTConvert.nsString(params["cvc"])
Expand Down
2 changes: 1 addition & 1 deletion src/types/PaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export namespace PaymentMethodCreateParams {
export type CardParams =
| (BaseParams & {
type: 'Card';
cardDetails: CardFieldInput.Details;
cardDetails: CardFieldInput.Details | { token: string };
setupFutureUsage?: PaymentIntents.FutureUsage;
})
| (BaseParams & {
Expand Down

0 comments on commit 9238180

Please sign in to comment.