use of movile.com.creditcardguide.model.CreditCardPaymentMethod in project CreditCardView by Movile.
the class CreditCardFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewHolder = view;
bindAttr();
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
backFinish.set(false);
Step step = pages.get(position);
if (step == Step.FLAG) {
hideKeyboard();
}
if (step != Step.CVV) {
cardRestored = false;
}
setNavigationButtons(step, false);
lastStep = step;
pageChanged();
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
setIssuerCode(IssuerCode.OTHER);
btNext.setVisibility(View.INVISIBLE);
btNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (btNext.isActivated()) {
nextPage();
} else {
shakeField();
}
}
});
editNumberCard.addTextChangedListener(this);
editNumberCard.setOnEditorActionListener(this);
editNumberCard.setTag(new FieldValidator() {
@Override
public boolean isValid() {
return validator.validateCreditCardNumber(editNumberCard, false);
}
});
editExpireCard.addTextChangedListener(this);
editExpireCard.setOnEditorActionListener(this);
editExpireCard.setTag(new FieldValidator() {
@Override
public boolean isValid() {
return validator.validateExpiredDate(editExpireCard, false);
}
});
editCVVCard.addTextChangedListener(this);
editCVVCard.setOnEditorActionListener(this);
editCVVCard.setOnFocusChangeListener(this);
editCVVCard.setTag(new FieldValidator() {
@Override
public boolean isValid() {
return validator.validateSecurityCode(selectedPurchaseOption.getIssuerCode(), editCVVCard, false);
}
});
editNameCard.addTextChangedListener(this);
editNameCard.setOnFocusChangeListener(this);
editNameCard.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
editNameCard.setTag(new FieldValidator() {
@Override
public boolean isValid() {
return validator.validateCreditCardName(editNameCard, false);
}
});
btEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cardRestored = false;
showEditCardLayout(true);
}
});
btPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer installments = (Integer) spInstallments.getSelectedItem();
if (validator.validateSecurityCode(selectedPurchaseOption.getIssuerCode(), editCVVCard, false)) {
if (validator.validateCreditCardFlag(selectedPurchaseOption, installments)) {
CreditCardPaymentMethod creditCardMethod = new CreditCardPaymentMethod();
creditCardMethod.setCreditCardNumber(editNumberCard.getText().toString().replaceAll(" ", ""));
creditCardMethod.setIssuerCode(selectedPurchaseOption.getIssuerCode());
creditCardMethod.setSecurityCode(editCVVCard.getText().toString());
creditCardMethod.setCreditCardName(editNameCard.getText().toString());
creditCardMethod.setInstallments(installments);
applyExpiredDate(creditCardMethod);
if (actionOnPayListener != null) {
actionOnPayListener.onComplete(creditCardMethod, switchSaveCard.isChecked());
}
} else {
// TODO: soft bug
Toast.makeText(getActivity(), R.string.invalid_credit_card_flag, Toast.LENGTH_LONG).show();
}
} else {
pager.setCurrentItem(pages.indexOf(Step.CVV));
showEditCardLayout(false);
showKeyboard(editCVVCard);
}
}
});
}
Aggregations