diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..dc178bd --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/android_volley_1_0_0.xml b/.idea/libraries/android_volley_1_0_0.xml new file mode 100644 index 0000000..33ad956 --- /dev/null +++ b/.idea/libraries/android_volley_1_0_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_25_3_1.xml b/.idea/libraries/animated_vector_drawable_25_3_1.xml new file mode 100644 index 0000000..c0811a6 --- /dev/null +++ b/.idea/libraries/animated_vector_drawable_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_25_3_1.xml b/.idea/libraries/appcompat_v7_25_3_1.xml new file mode 100644 index 0000000..3a0494c --- /dev/null +++ b/.idea/libraries/appcompat_v7_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/constraint_layout_1_0_1.xml b/.idea/libraries/constraint_layout_1_0_1.xml new file mode 100644 index 0000000..a5a4da8 --- /dev/null +++ b/.idea/libraries/constraint_layout_1_0_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/constraint_layout_solver_1_0_1.xml b/.idea/libraries/constraint_layout_solver_1_0_1.xml new file mode 100644 index 0000000..496104c --- /dev/null +++ b/.idea/libraries/constraint_layout_solver_1_0_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/espresso_core_2_2_2.xml b/.idea/libraries/espresso_core_2_2_2.xml new file mode 100644 index 0000000..86c335d --- /dev/null +++ b/.idea/libraries/espresso_core_2_2_2.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/espresso_idling_resource_2_2_2.xml b/.idea/libraries/espresso_idling_resource_2_2_2.xml new file mode 100644 index 0000000..0dc7dc3 --- /dev/null +++ b/.idea/libraries/espresso_idling_resource_2_2_2.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml b/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml new file mode 100644 index 0000000..aed587c --- /dev/null +++ b/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/gson_2_8_0.xml b/.idea/libraries/gson_2_8_0.xml new file mode 100644 index 0000000..0e2abf0 --- /dev/null +++ b/.idea/libraries/gson_2_8_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest_core_1_3.xml b/.idea/libraries/hamcrest_core_1_3.xml new file mode 100644 index 0000000..157e3f3 --- /dev/null +++ b/.idea/libraries/hamcrest_core_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest_integration_1_3.xml b/.idea/libraries/hamcrest_integration_1_3.xml new file mode 100644 index 0000000..58b2c4b --- /dev/null +++ b/.idea/libraries/hamcrest_integration_1_3.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest_library_1_3.xml b/.idea/libraries/hamcrest_library_1_3.xml new file mode 100644 index 0000000..676cc63 --- /dev/null +++ b/.idea/libraries/hamcrest_library_1_3.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/javawriter_2_1_1.xml b/.idea/libraries/javawriter_2_1_1.xml new file mode 100644 index 0000000..a66fefb --- /dev/null +++ b/.idea/libraries/javawriter_2_1_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/javax_annotation_api_1_2.xml b/.idea/libraries/javax_annotation_api_1_2.xml new file mode 100644 index 0000000..811e73f --- /dev/null +++ b/.idea/libraries/javax_annotation_api_1_2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/javax_inject_1.xml b/.idea/libraries/javax_inject_1.xml new file mode 100644 index 0000000..0d1d5fc --- /dev/null +++ b/.idea/libraries/javax_inject_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/jsr305_2_0_1.xml b/.idea/libraries/jsr305_2_0_1.xml new file mode 100644 index 0000000..cdf9878 --- /dev/null +++ b/.idea/libraries/jsr305_2_0_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/junit_4_12.xml b/.idea/libraries/junit_4_12.xml new file mode 100644 index 0000000..305df30 --- /dev/null +++ b/.idea/libraries/junit_4_12.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/rules_0_5.xml b/.idea/libraries/rules_0_5.xml new file mode 100644 index 0000000..1d51e0a --- /dev/null +++ b/.idea/libraries/rules_0_5.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/runner_0_5.xml b/.idea/libraries/runner_0_5.xml new file mode 100644 index 0000000..db91766 --- /dev/null +++ b/.idea/libraries/runner_0_5.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_annotations_25_3_1.xml b/.idea/libraries/support_annotations_25_3_1.xml new file mode 100644 index 0000000..42adfc6 --- /dev/null +++ b/.idea/libraries/support_annotations_25_3_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_compat_25_3_1.xml b/.idea/libraries/support_compat_25_3_1.xml new file mode 100644 index 0000000..aee35a5 --- /dev/null +++ b/.idea/libraries/support_compat_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_ui_25_3_1.xml b/.idea/libraries/support_core_ui_25_3_1.xml new file mode 100644 index 0000000..b80d99d --- /dev/null +++ b/.idea/libraries/support_core_ui_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_utils_25_3_1.xml b/.idea/libraries/support_core_utils_25_3_1.xml new file mode 100644 index 0000000..2dd66dd --- /dev/null +++ b/.idea/libraries/support_core_utils_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_fragment_25_3_1.xml b/.idea/libraries/support_fragment_25_3_1.xml new file mode 100644 index 0000000..a4fffd6 --- /dev/null +++ b/.idea/libraries/support_fragment_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_media_compat_25_3_1.xml b/.idea/libraries/support_media_compat_25_3_1.xml new file mode 100644 index 0000000..d61962d --- /dev/null +++ b/.idea/libraries/support_media_compat_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_v4_25_3_1.xml b/.idea/libraries/support_v4_25_3_1.xml new file mode 100644 index 0000000..3028232 --- /dev/null +++ b/.idea/libraries/support_v4_25_3_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_25_3_1.xml b/.idea/libraries/support_vector_drawable_25_3_1.xml new file mode 100644 index 0000000..e2e8d1f --- /dev/null +++ b/.idea/libraries/support_vector_drawable_25_3_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9fc28d4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..549ad90 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..76588ae --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "ch.itomy.xendit_example" + minSdkVersion 9 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.android.support.constraint:constraint-layout:1.0.1' + testCompile 'junit:junit:4.12' + compile project(':xendit-android') +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..c59202b --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/SergeyOmelyanovskiy/AndroidStudio/android-sdk-macosx/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/ch/itomy/xendit_example/ExampleInstrumentedTest.java b/app/src/androidTest/java/ch/itomy/xendit_example/ExampleInstrumentedTest.java new file mode 100644 index 0000000..38b648f --- /dev/null +++ b/app/src/androidTest/java/ch/itomy/xendit_example/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package ch.itomy.xendit_example; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("ch.itomy.xendit_example", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..af8c091 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/ch/itomy/xendit_example/AuthenticationActivity.java b/app/src/main/java/ch/itomy/xendit_example/AuthenticationActivity.java new file mode 100644 index 0000000..a7a54dd --- /dev/null +++ b/app/src/main/java/ch/itomy/xendit_example/AuthenticationActivity.java @@ -0,0 +1,88 @@ +package ch.itomy.xendit_example; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.xendit.Models.Card; +import com.xendit.Models.Token; +import com.xendit.Models.XenditError; +import com.xendit.TokenCallback; +import com.xendit.Xendit; + +/** + * Created by Sergey on 4/3/17. + */ + +public class AuthenticationActivity extends AppCompatActivity implements View.OnClickListener { + + private EditText tokenIdEditText; + private EditText amountEditText; + private EditText cardCvnEditText; + private Button authenticateBtn; + + public static Intent getLaunchIntent(Context context) { + return new Intent(context, AuthenticationActivity.class); + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_authentication); + + setActionBarTitle("Authentication"); + + tokenIdEditText = (EditText) findViewById(R.id.tokenIdEditText_AuthenticationActivity); + amountEditText = (EditText) findViewById(R.id.amountEditText_AuthenticationActivity); + cardCvnEditText = (EditText) findViewById(R.id.cardCvnEditText_AuthenticationActivity); + authenticateBtn = (Button) findViewById(R.id.authenticateBtn_AuthenticationActivity); + + authenticateBtn.setOnClickListener(this); + } + + private void setActionBarTitle(String title) { + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle(title); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + } + } + + @Override + public void onClick(View view) { + Card card = new Card("4000000000000002", "12", "2017", cardCvnEditText.getText().toString()); + + Xendit xendit = new Xendit(getApplicationContext(), CreateTokenActivity.PUBLISH_KEY); + xendit.createAuthentication(card, tokenIdEditText.getText().toString(), amountEditText.getText().toString(), new TokenCallback() { + @Override + public void onSuccess(Token token) { + Toast.makeText(AuthenticationActivity.this, "Status: " + token.getAuthentication().getStatus(), Toast.LENGTH_SHORT).show(); + } + + @Override + public void onError(XenditError xenditError) { + Toast.makeText(AuthenticationActivity.this, xenditError.getError(), Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + this.finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ch/itomy/xendit_example/CreateTokenActivity.java b/app/src/main/java/ch/itomy/xendit_example/CreateTokenActivity.java new file mode 100644 index 0000000..1dc93e4 --- /dev/null +++ b/app/src/main/java/ch/itomy/xendit_example/CreateTokenActivity.java @@ -0,0 +1,103 @@ +package ch.itomy.xendit_example; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.xendit.Models.Card; +import com.xendit.Models.Token; +import com.xendit.Models.XenditError; +import com.xendit.TokenCallback; +import com.xendit.Xendit; + +/** + * Created by Sergey on 4/3/17. + */ + +public class CreateTokenActivity extends AppCompatActivity implements View.OnClickListener { + + public static final String PUBLISH_KEY = "xnd_public_development_O4iFfuQhgLOsl8M9eeEYGzeWYNH3otV5w3Dh/BFj/mHW+72nCQR/"; + + private EditText cardNumberEditText; + private EditText expMonthEditText; + private EditText expYearEditText; + private EditText cvnEditText; + private EditText amountEditText; + private Button createTokenBtn; + + public static Intent getLaunchIntent(Context context) { + return new Intent(context, CreateTokenActivity.class); + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_create_token); + + setActionBarTitle("Create Token"); + + cardNumberEditText = (EditText) findViewById(R.id.cardNumberEditText_CreateTokenActivity); + expMonthEditText = (EditText) findViewById(R.id.expMonthEditText_CreateTokenActivity); + expYearEditText = (EditText) findViewById(R.id.expYearEditText_CreateTokenActivity); + cvnEditText = (EditText) findViewById(R.id.cvnEditText_CreateTokenActivity); + amountEditText = (EditText) findViewById(R.id.amountEditText_CreateTokenActivity); + createTokenBtn = (Button) findViewById(R.id.createTokenBtn_CreateTokenActivity); + + createTokenBtn.setOnClickListener(this); + + cardNumberEditText.setText("4000000000000002"); + expMonthEditText.setText("12"); + expYearEditText.setText("2017"); + cvnEditText.setText("123"); + amountEditText.setText("222"); + } + + private void setActionBarTitle(String title) { + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle(title); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + } + } + + @Override + public void onClick(View view) { + Card card = new Card(cardNumberEditText.getText().toString(), + expMonthEditText.getText().toString(), + expYearEditText.getText().toString(), + cvnEditText.getText().toString()); + + Xendit xendit = new Xendit(getApplicationContext(), PUBLISH_KEY); + xendit.createToken(card, amountEditText.getText().toString(), new TokenCallback() { + @Override + public void onSuccess(Token token) { + Toast.makeText(CreateTokenActivity.this, "Status: " + token.getAuthentication().getStatus(), Toast.LENGTH_SHORT).show(); + } + + @Override + public void onError(XenditError xenditError) { + Toast.makeText(CreateTokenActivity.this, xenditError.getError(), Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + this.finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ch/itomy/xendit_example/MainActivity.java b/app/src/main/java/ch/itomy/xendit_example/MainActivity.java new file mode 100644 index 0000000..d808e16 --- /dev/null +++ b/app/src/main/java/ch/itomy/xendit_example/MainActivity.java @@ -0,0 +1,52 @@ +package ch.itomy.xendit_example; + +import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.TextView; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + + private TextView createTokenTextView; + private TextView authenticationTextView; + private TextView validationUtilTextView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + setActionBarTitle("Xendit"); + + createTokenTextView = (TextView) findViewById(R.id.createTokenTextView_MainActivity); + authenticationTextView = (TextView) findViewById(R.id.authenticationTextView_MainActivity); + validationUtilTextView = (TextView) findViewById(R.id.validationUtilTextView_MainActivity); + + createTokenTextView.setOnClickListener(this); + authenticationTextView.setOnClickListener(this); + validationUtilTextView.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.createTokenTextView_MainActivity: + startActivity(CreateTokenActivity.getLaunchIntent(this)); + break; + case R.id.authenticationTextView_MainActivity: + startActivity(AuthenticationActivity.getLaunchIntent(this)); + break; + case R.id.validationUtilTextView_MainActivity: + startActivity(ValidationUtilActivity.getLaunchIntent(this)); + break; + } + } + + private void setActionBarTitle(String title) { + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle(title); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ch/itomy/xendit_example/ValidationUtilActivity.java b/app/src/main/java/ch/itomy/xendit_example/ValidationUtilActivity.java new file mode 100644 index 0000000..5b70409 --- /dev/null +++ b/app/src/main/java/ch/itomy/xendit_example/ValidationUtilActivity.java @@ -0,0 +1,85 @@ +package ch.itomy.xendit_example; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.xendit.Xendit; + +/** + * Created by Sergey on 4/3/17. + */ + +public class ValidationUtilActivity extends AppCompatActivity implements View.OnClickListener { + + private EditText cardNumberEditText; + private EditText expMonthEditText; + private EditText expYearEditText; + private EditText cvnEditText; + private Button validateBtn; + + public static Intent getLaunchIntent(Context context) { + return new Intent(context, ValidationUtilActivity.class); + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_validation_util); + + setActionBarTitle("Validation Util"); + + cardNumberEditText = (EditText) findViewById(R.id.cardNumberEditText_ValidationUtilActivity); + expMonthEditText = (EditText) findViewById(R.id.expMonthEditText_ValidationUtilActivity); + expYearEditText = (EditText) findViewById(R.id.expYearEditText_ValidationUtilActivity); + cvnEditText = (EditText) findViewById(R.id.cvnEditText_ValidationUtilActivity); + validateBtn = (Button) findViewById(R.id.validateBtn_ValidationUtilActivity); + + validateBtn.setOnClickListener(this); + } + + private void setActionBarTitle(String title) { + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle(title); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + } + } + + @Override + public void onClick(View view) { + + + if (!Xendit.isCardNumberValid(cardNumberEditText.getText().toString())) { + Toast.makeText(this, "Card number is invalid", Toast.LENGTH_SHORT).show(); + } else if (!Xendit.isExpiryValid(expMonthEditText.getText().toString(), expYearEditText.getText().toString())) { + Toast.makeText(this, "Card expiration date is invalid", Toast.LENGTH_SHORT).show(); + } else if (!Xendit.isCvnValid(cvnEditText.getText().toString())) { + Toast.makeText(this, "Card cvn is invalid", Toast.LENGTH_SHORT).show(); + } else if (Xendit.isCardNumberValid(cardNumberEditText.getText().toString()) + && Xendit.isExpiryValid(expMonthEditText.getText().toString(), expYearEditText.getText().toString()) + && Xendit.isCvnValid(cvnEditText.getText().toString())) { + Toast.makeText(this, "Card is valid", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + this.finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_authentication.xml b/app/src/main/res/layout/activity_authentication.xml new file mode 100644 index 0000000..5192f2d --- /dev/null +++ b/app/src/main/res/layout/activity_authentication.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + +