Skip to content

Commit

Permalink
Release v1.6.14 (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Kos authored Sep 16, 2021
1 parent a740c47 commit fec43d6
Show file tree
Hide file tree
Showing 128 changed files with 8,805 additions and 545 deletions.
7 changes: 7 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Migration Guides

### Migrating from versions < v1.6.14

Field state will be valid if no validation rules defined.

### Migrating from versions < v1.6.5

#### VGSEditText
Expand All @@ -10,6 +14,9 @@ Remove `setFieldType` method from code in case you use it.
Please use `VGSCardNumberEditText`, `ExpirationDateEditText`, `CardVerificationCodeEditText`, `PersonNameEditText`, `SSNEditText`
specific fields instead of `app:fieldType` attribute or `FieldType` enum class.

Field which doesn't have validation rules will have invalid state, by default.
In case you don't need validation for VGSEditText then set `app:enableValidation="false"` in XML.


### Migrating from versions < v1.6.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ class ActivityCaseInstrumentedTest {
const val CARD_NUMBER_WRONG_2 = "41111111111111112"

const val CARD_HOLDER_WRONG = "Gohn Galt, I."
const val CARD_HOLDER= "Gohn G"
const val CARD_HOLDER = "Gohn G"

const val CARD_EXP_DATE_WRONG = "22/2222"
const val CARD_EXP_DATE= "02/25"
const val CARD_EXP_DATE = "02/25"

const val CARD_CVC_WRONG = "12"
const val CARD_CVC= "123"
const val CARD_CVC = "123"

const val CODE_200= "Code: 200"
const val CODE_1001= "Code: 1001"
const val POSTAL_WRONG = "12"
const val POSTAL = "12345"

const val CITY = "new city"

const val CODE_200 = "Code: 200"
const val CODE_1001 = "Code: 1001"
}

@get:Rule
Expand All @@ -74,12 +79,12 @@ class ActivityCaseInstrumentedTest {

interactWithScanner()

val submitBtn = interactWithSubmitButton()
val submitBtn = interactWithSubmitButton()
performClick(submitBtn)

pauseTestFor(7000)

val responseContainer = interactWithResponseContainer()
val responseContainer = interactWithResponseContainer()
responseContainer.check(matches(withText(containsString(CODE_200))))

release()
Expand All @@ -88,7 +93,7 @@ class ActivityCaseInstrumentedTest {

fun interactWithScanner() = apply {
val intent = Intent()
val card = CreditCard("4111111111111111", 5,2033, "123", null, "John B")
val card = CreditCard("4111111111111111", 5, 2033, "123", null, "John B")
intent.putExtra(CardIOActivity.EXTRA_SCAN_RESULT, card)


Expand Down Expand Up @@ -133,9 +138,11 @@ class ActivityCaseInstrumentedTest {
fun test_submit_flow() {
startMainScreen()

val responseContainer = interactWithResponseContainer()
val submitBtn = interactWithSubmitButton()
val responseContainer = interactWithResponseContainer()
val submitBtn = interactWithSubmitButton()

val postalCode = interactWithPostalCode()
val city = interactWithCity()
val cardInputField = interactWithCardNumber()
val cardHolderNameInputField = interactWithCardHolderName()
val cardExpDateInputField = interactWithCardExpDate()
Expand Down Expand Up @@ -169,6 +176,13 @@ class ActivityCaseInstrumentedTest {
performClick(submitBtn)
responseContainer.check(matches(withText(containsString(CODE_1001))))
cardInputField.perform(SetTextAction(CARD_NUMBER))

postalCode.perform(SetTextAction(POSTAL_WRONG))
performClick(submitBtn)
responseContainer.check(matches(withText(containsString(CODE_1001))))

postalCode.perform(SetTextAction(POSTAL))
city.perform(SetTextAction(CITY))
performClick(submitBtn)

pauseTestFor(7000)
Expand All @@ -185,7 +199,10 @@ class ActivityCaseInstrumentedTest {
val startWithActivityBtn = onView(withId(R.id.startWithActivityBtn))
.check(matches(isDisplayed()))

onView(withId(R.id.userVault)).perform(typeText(Utils.DEFAULT_TENANT_ID), closeSoftKeyboard())
onView(withId(R.id.userVault)).perform(
typeText(Utils.DEFAULT_TENANT_ID),
closeSoftKeyboard()
)
onView(withId(R.id.userPath)).perform(typeText(Utils.DEFAULT_PATH), closeSoftKeyboard())

performClick(startWithActivityBtn)
Expand Down Expand Up @@ -218,6 +235,16 @@ class ActivityCaseInstrumentedTest {
return cardHolderField
}

private fun interactWithCity(): ViewInteraction {
return onView(withId(R.id.cityField))
.check(matches(not(isDisplayed())))
}

private fun interactWithPostalCode(): ViewInteraction {
return onView(withId(R.id.postalCodeField))
.check(matches(not(isDisplayed())))
}

private fun interactWithCardNumber(): ViewInteraction {
val cardInputField = onView(withId(R.id.cardNumberField))
.check(matches(not(isDisplayed())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,17 @@ class VGSEditTextActivityValidationInstrumentedTest {

@Test
fun test_editText_disable_validation() {
Espresso.onView(ViewMatchers.withId(R.id.disableValidationBtn))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.perform(ViewActions.click())

val field = Espresso.onView(ViewMatchers.withId(R.id.vgsEditText))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

field.perform(SetTextAction(NAME_WRONG_1))
field.check(ViewAssertions.matches(WithValidationStateMatcher()))
field.check(ViewAssertions.matches(CoreMatchers.not(WithValidationStateMatcher())))

Espresso.onView(ViewMatchers.withId(R.id.disableValidationBtn))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.perform(ViewActions.click())

field.perform(SetTextAction(NAME_WRONG_1))
field.check(ViewAssertions.matches(CoreMatchers.not(WithValidationStateMatcher())))
field.perform(SetTextAction(NAME_CORRECT))
field.check(ViewAssertions.matches(WithValidationStateMatcher()))
}

private fun pauseTestFor(milliseconds: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ import com.verygoodsecurity.vgscollect.view.card.icon.CardIconAdapter
import com.verygoodsecurity.vgscollect.view.card.validation.payment.ChecksumAlgorithm
import com.verygoodsecurity.vgscollect.view.card.validation.rules.PaymentCardNumberRule
import com.verygoodsecurity.vgscollect.view.card.validation.rules.PersonNameRule
import com.verygoodsecurity.vgscollect.view.card.validation.rules.VGSInfoRule
import kotlinx.android.synthetic.main.activity_collect_demo.*

class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.OnClickListener {
class VGSCollectActivity : AppCompatActivity(), VgsCollectResponseListener, View.OnClickListener {

companion object {
const val USER_SCAN_REQUEST_CODE = 0x7
}

private lateinit var vault_id:String
private lateinit var path:String
private lateinit var env:Environment
private lateinit var vault_id: String
private lateinit var path: String
private lateinit var env: Environment

private lateinit var vgsForm: VGSCollect

Expand All @@ -61,12 +62,30 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
setupCVCField()
setupCardHolderField()
setupCardExpDateField()
setupPostalCodeField()
setupCityField()

val staticData = mutableMapOf<String, String>()
staticData["static_data"] = "static custom data"
vgsForm.setCustomData(staticData)
}

private fun setupCityField() {
vgsForm.bindView(cityField)
}

private fun setupPostalCodeField() {
postalCodeField?.apply {
addRule(
VGSInfoRule.ValidationBuilder()
.setRegex("^[0-9]{5}(?:-[0-9]{4})?\$")
.build()
)
}

vgsForm.bindView(postalCodeField)
}

private fun setupCardExpDateField() {
vgsForm.bindView(cardExpDateField)
cardExpDateField?.setOnFieldStateChangeListener(object : OnFieldStateChangeListener {
Expand All @@ -81,7 +100,7 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
}

private fun setupCardHolderField() {
val rule : PersonNameRule = PersonNameRule.ValidationBuilder()
val rule: PersonNameRule = PersonNameRule.ValidationBuilder()
.setAllowableMinLength(3)
.setAllowableMaxLength(7)
.build()
Expand Down Expand Up @@ -114,7 +133,7 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
}

private fun setupDefaultBehaviour() {
val rule : PaymentCardNumberRule = PaymentCardNumberRule.ValidationBuilder()
val rule: PaymentCardNumberRule = PaymentCardNumberRule.ValidationBuilder()
// .setAlgorithm(ChecksumAlgorithm.NONE)

.setAllowableNumberLength(arrayOf(15, 13, 19))
Expand Down Expand Up @@ -214,10 +233,10 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.

val bndl = intent?.extras

vault_id = bndl?.getString(StartActivity.VAULT_ID, "")?:""
path = bndl?.getString(StartActivity.PATH, "/")?:""
vault_id = bndl?.getString(StartActivity.VAULT_ID, "") ?: ""
path = bndl?.getString(StartActivity.PATH, "/") ?: ""

val envId = bndl?.getInt(StartActivity.ENVIROMENT, 0)?:0
val envId = bndl?.getInt(StartActivity.ENVIROMENT, 0) ?: 0
env = Environment.values()[envId]

vgsForm = VGSCollect.Builder(this, vault_id)
Expand All @@ -238,7 +257,7 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if(item.itemId == R.id.scan_card) {
return if (item.itemId == R.id.scan_card) {
scanCard()
true
} else {
Expand All @@ -265,23 +284,12 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
return object : OnFieldStateChangeListener {
override fun onStateChange(state: FieldState) {
Log.e("vgs_collect_state", "$state ")
when(state) {
is FieldState.CardNumberState -> handleCardNumberState(state)
}

refreshAllStates()
}
}
}

private fun handleCardNumberState(state: FieldState.CardNumberState) {
previewCardNumber?.text = state.number
if(state.cardBrand == CardType.VISA.name) {
previewCardBrand?.setImageResource(R.drawable.ic_custom_visa)
} else {
previewCardBrand?.setImageResource(state.drawableBrandResId)
}
}

private fun refreshAllStates() {
val states = vgsForm.getAllStates()
val builder = StringBuilder()
Expand All @@ -308,7 +316,7 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
}

private fun checkAttachedFiles() {
if(vgsForm.getFileProvider().getAttachedFiles().isEmpty()) {
if (vgsForm.getFileProvider().getAttachedFiles().isEmpty()) {
attachBtn?.text = getString(R.string.collect_activity_attach_btn)
} else {
attachBtn?.text = getString(R.string.collect_activity_detach_btn)
Expand All @@ -320,13 +328,14 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
setStateLoading(false)

when (response) {
is VGSResponse.SuccessResponse -> responseContainerView.text = "Code: ${response.successCode}"
is VGSResponse.SuccessResponse -> responseContainerView.text =
"Code: ${response.successCode}"
is VGSResponse.ErrorResponse -> responseContainerView.text = response.toString()
}
}

private fun setStateLoading(state: Boolean) {
if(state) {
if (state) {
progressBar?.visibility = View.VISIBLE
submitBtn?.isEnabled = false
attachBtn?.isEnabled = false
Expand All @@ -338,7 +347,7 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
}

private fun setEnabledResponseHeader(isEnabled: Boolean) {
if(isEnabled) {
if (isEnabled) {
attachBtn.setTextColor(
ContextCompat.getColor(this, R.color.state_active)
)
Expand Down Expand Up @@ -378,7 +387,7 @@ class VGSCollectActivity: AppCompatActivity(), VgsCollectResponseListener, View.
}

private fun attachFile() {
if(vgsForm.getFileProvider().getAttachedFiles().isEmpty()) {
if (vgsForm.getFileProvider().getAttachedFiles().isEmpty()) {
vgsForm.getFileProvider().attachFile("attachments.file")
} else {
vgsForm.getFileProvider().detachAll()
Expand Down
Loading

0 comments on commit fec43d6

Please sign in to comment.