package com.mobilhanem.androidcardio;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import io.card.payment.CardIOActivity;
import io.card.payment.CreditCard;
public class MainActivity extends AppCompatActivity {
private Button scanBttn;
private TextView scanInfo;
private int MY_SCAN_REQUEST_CODE = 999;
@Override
protected void onResume() {
super.onResume();
if (CardIOActivity.canReadCardWithCamera()) { //Kameradan okutma yapılıyorsa
scanBttn.setText(“Kredi Kartını Okut”);
} else {
scanBttn.setText(“Kredi Kartı Bilgilerini Giriniz”);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanBttn = (Button)findViewById(R.id.scanButton);
scanInfo = (TextView)findViewById(R.id.txtScan);
scanBttn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scanCreditCard();
}
});
}
private void scanCreditCard() {
Intent scanIntent = new Intent(this, CardIOActivity.class);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CARDHOLDER_NAME, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_KEEP_APPLICATION_THEME, false); // default: false
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String resultStr;
if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
resultStr = “Card Number: “ + scanResult.getLastFourDigitsOfCardNumber() + “n”;
if (scanResult.isExpiryValid()) {
resultStr += “Expiration Date: “ + scanResult.expiryMonth + “/” + scanResult.expiryYear + “n”;
}
if (scanResult.cvv != null) {
resultStr += “CVV has “ + scanResult.cvv.length() + ” digits.n”;
}
if (scanResult.postalCode != null) {
resultStr += “Postal Code: “ + scanResult.postalCode + “n”;
}
if (scanResult.cardholderName != null) {
resultStr += “Cardholder Name : “ + scanResult.cardholderName + “n”;
}
} else {
resultStr = “Tarama İptal Edildi.”;
}
scanInfo.setText(resultStr);
}
}