This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Issue #10205: Add support for select credit card prompt #10213
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit strange to have an identifier that can be null? Would you mind helping me to clarify this part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because of GV's Credit Card guid can be nullable. https://mozilla.github.io/geckoview/javadoc/mozilla-central/org/mozilla/geckoview/Autocomplete.CreditCard.html#guid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems odd. Maybe there is a mistake in the API? The other fields are non-null, so a GUID should also be non-null.