forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#10205: Add support for select credit card prompt
- Implements an override function of `onCreditCardSelect` in `GeckoPromptDelegate` - Adds a new `CreditCard` data class in `concept-engine`. This is a parallel of GV's `Autocomplete.CreditCard`. We can't using the existing `CreditCard` from `concept-storage` since that has encryption dependencies whereas the card number is already decrypted when it reaches GV. - Adds a new `SelectCreditCard` in `PromptRequest`
- Loading branch information
1 parent
471da2b
commit bf725a2
Showing
9 changed files
with
289 additions
and
5 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...wser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/ext/CreditCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.browser.engine.gecko.ext | ||
|
||
import mozilla.components.concept.engine.prompt.CreditCard | ||
import org.mozilla.geckoview.Autocomplete | ||
|
||
// Placeholder for the card type. This will be replaced when we can identify the card type. | ||
// This is dependent on https://github.com/mozilla-mobile/android-components/issues/9813. | ||
private const val CARD_TYPE_PLACEHOLDER = "" | ||
|
||
/** | ||
* Converts a GeckoView [Autocomplete.CreditCard] to an Android Components [CreditCard]. | ||
*/ | ||
fun Autocomplete.CreditCard.toCreditCard() = CreditCard( | ||
guid = guid, | ||
name = name, | ||
number = number, | ||
expiryMonth = expirationMonth, | ||
expiryYear = expirationYear, | ||
cardType = CARD_TYPE_PLACEHOLDER | ||
) | ||
|
||
/** | ||
* Converts an Android Components [CreditCard] to a GeckoView [Autocomplete.CreditCard]. | ||
*/ | ||
fun CreditCard.toAutocompleteCreditCard() = Autocomplete.CreditCard.Builder() | ||
.guid(guid) | ||
.name(name) | ||
.number(number) | ||
.expirationMonth(expiryMonth) | ||
.expirationYear(expiryYear) | ||
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...nents/concept/engine/src/main/java/mozilla/components/concept/engine/prompt/CreditCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.concept.engine.prompt | ||
|
||
import android.os.Parcelable | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
/** | ||
* Value type that represents a credit card. | ||
* | ||
* @property guid The unique identifier for this credit card. | ||
* @property name The credit card billing name. | ||
* @property number The credit card number. | ||
* @property expiryMonth The credit card expiry month. | ||
* @property expiryYear The credit card expiry year. | ||
* @property cardType The credit card network ID. | ||
*/ | ||
@Parcelize | ||
data class CreditCard( | ||
val guid: String?, | ||
val name: String, | ||
val number: String, | ||
val expiryMonth: String, | ||
val expiryYear: String, | ||
val cardType: String | ||
) : Parcelable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...s/concept/engine/src/test/java/mozilla/components/concept/engine/prompt/CreditCardTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.concept.engine.prompt | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class CreditCardTest { | ||
|
||
@Test | ||
fun `Create a CreditCard`() { | ||
val guid = "1" | ||
val name = "Banana Apple" | ||
val number = "4111111111111110" | ||
val expiryMonth = "5" | ||
val expiryYear = "2030" | ||
val cardType = "amex" | ||
val creditCard = CreditCard( | ||
guid = guid, | ||
name = name, | ||
number = number, | ||
expiryMonth = expiryMonth, | ||
expiryYear = expiryYear, | ||
cardType = cardType | ||
) | ||
|
||
assertEquals(guid, creditCard.guid) | ||
assertEquals(name, creditCard.name) | ||
assertEquals(number, creditCard.number) | ||
assertEquals(expiryMonth, creditCard.expiryMonth) | ||
assertEquals(expiryYear, creditCard.expiryYear) | ||
assertEquals(cardType, creditCard.cardType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.