diff --git a/.gitignore b/.gitignore index 4d7d435..09a22e5 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,5 @@ molpayxdk/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin .gradle/checksums/sha1-checksums.bin .idea/compiler.xml .idea/gradle.xml +.gradle/config.properties +molpayxdk/build/ diff --git a/app/build.gradle b/app/build.gradle index fd394ec..d227c4d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 32 + compileSdk 34 defaultConfig { applicationId "com.molpay.molpayxdkproject" - minSdkVersion 16 - targetSdkVersion 32 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 versionName "1.0" + multiDexEnabled true } buildTypes { release { @@ -16,12 +17,18 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + namespace 'com.molpay.molpayxdkproject' + + viewBinding { + enabled = true + } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - testImplementation 'junit:junit:4.12' - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'com.google.android.material:material:1.5.0' + implementation 'com.google.android.gms:play-services-wallet:19.3.0' + testImplementation 'junit:junit:4.13.2' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.12.0' implementation project(':molpayxdk') } diff --git a/app/src/androidTest/java/com/molpay/molpayxdkproject/ApplicationTest.java b/app/src/androidTest/java/com/molpay/molpayxdkproject/ApplicationTest.java deleted file mode 100644 index 034678d..0000000 --- a/app/src/androidTest/java/com/molpay/molpayxdkproject/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.molpay.molpayxdkproject; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8471289..1ccab7c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,6 +39,11 @@ + + + diff --git a/app/src/main/java/com/molpay/molpayxdkproject/MainActivity.java b/app/src/main/java/com/molpay/molpayxdkproject/MainActivity.java index 26f06b9..5f87d79 100644 --- a/app/src/main/java/com/molpay/molpayxdkproject/MainActivity.java +++ b/app/src/main/java/com/molpay/molpayxdkproject/MainActivity.java @@ -9,17 +9,27 @@ import android.view.MenuItem; import android.widget.TextView; +import com.google.android.gms.wallet.button.ButtonConstants; +import com.google.android.gms.wallet.button.ButtonOptions; +import com.google.android.gms.wallet.button.PayButton; import com.molpay.molpayxdk.MOLPayActivity; +import com.molpay.molpayxdk.googlepay.ActivityGP; +import com.molpay.molpayxdk.googlepay.UtilGP; + +import org.json.JSONException; import java.util.Calendar; import java.util.HashMap; public class MainActivity extends AppCompatActivity { + private PayButton googlePayButton; + private void restartmolpay() { HashMap paymentDetails = new HashMap<>(); paymentDetails.put(MOLPayActivity.mp_amount, "1.10"); + // TODO: Enter your merchant account credentials before test run paymentDetails.put(MOLPayActivity.mp_username, ""); paymentDetails.put(MOLPayActivity.mp_password, ""); paymentDetails.put(MOLPayActivity.mp_merchant_ID, ""); @@ -33,17 +43,48 @@ private void restartmolpay() { paymentDetails.put(MOLPayActivity.mp_bill_description, "bill description"); paymentDetails.put(MOLPayActivity.mp_bill_name, "bill name"); paymentDetails.put(MOLPayActivity.mp_bill_email, "example@gmail.com"); - paymentDetails.put(MOLPayActivity.mp_bill_mobile, "01234567888"); - paymentDetails.put(MOLPayActivity.mp_channel_editing, false); - paymentDetails.put(MOLPayActivity.mp_editing_enabled, true); - paymentDetails.put(MOLPayActivity.mp_express_mode, false); - paymentDetails.put(MOLPayActivity.mp_dev_mode, false); - paymentDetails.put(MOLPayActivity.mp_preferred_token, "new"); + paymentDetails.put(MOLPayActivity.mp_bill_mobile, "123456789"); + + // TODO: Learn more about optional parameters here https://github.com/RazerMS/Mobile-XDK-RazerMS_Android_Studio/wiki/Installation-Guidance#prepare-the-payment-detail-object +// paymentDetails.put(MOLPayActivity.mp_channel_editing, false); +// paymentDetails.put(MOLPayActivity.mp_editing_enabled, true); +// paymentDetails.put(MOLPayActivity.mp_express_mode, false); +// paymentDetails.put(MOLPayActivity.mp_dev_mode, false); +// paymentDetails.put(MOLPayActivity.mp_preferred_token, "new"); Intent intent = new Intent(MainActivity.this, MOLPayActivity.class); intent.putExtra(MOLPayActivity.MOLPayPaymentDetails, paymentDetails); startActivityForResult(intent, MOLPayActivity.MOLPayXDK); + } + + private void googlePayPayment() { + HashMap paymentDetails = new HashMap<>(); + /* + TODO: Follow Google’s instructions to request production access for your app: https://developers.google.com/pay/api/android/guides/test-and-deploy/request-prod-access + * + Choose the integration type Gateway when prompted, and provide screenshots of your app for review. + After your app has been approved, test your integration in production by set mp_sandbox_mode = false & use production mp_verification_key & mp_merchant_ID. + Then launching Google Pay from a signed, release build of your app. + */ + paymentDetails.put(MOLPayActivity.mp_sandbox_mode, true); // Only set to false once you have request production access for your app + + // TODO: Enter your merchant account credentials before test run + paymentDetails.put(MOLPayActivity.mp_merchant_ID, ""); // Your sandbox / production merchant ID + paymentDetails.put(MOLPayActivity.mp_verification_key, ""); // Your sandbox / production verification key + + paymentDetails.put(MOLPayActivity.mp_amount, "1.11"); // Must be in 2 decimal points format + paymentDetails.put(MOLPayActivity.mp_order_ID, Calendar.getInstance().getTimeInMillis()); // Must be unique + paymentDetails.put(MOLPayActivity.mp_currency, "MYR"); // Must matched mp_country + paymentDetails.put(MOLPayActivity.mp_country, "MY"); // Must matched mp_currency + paymentDetails.put(MOLPayActivity.mp_bill_description, "The bill description"); + paymentDetails.put(MOLPayActivity.mp_bill_name, "The bill name"); + paymentDetails.put(MOLPayActivity.mp_bill_email, "payer.email@fiuu.com"); + paymentDetails.put(MOLPayActivity.mp_bill_mobile, "123456789"); + + Intent intent = new Intent(MainActivity.this, ActivityGP.class); // Used ActivityGP for Google Pay + intent.putExtra(MOLPayActivity.MOLPayPaymentDetails, paymentDetails); + startActivityForResult(intent, MOLPayActivity.MOLPayXDK); } @Override @@ -51,6 +92,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); + Log.e("logGooglePay" , "onActivityResult requestCode = " + requestCode); + Log.e("logGooglePay" , "onActivityResult resultCode = " + resultCode); + if (requestCode == MOLPayActivity.MOLPayXDK && resultCode == RESULT_OK){ Log.d(MOLPayActivity.MOLPAY, "MOLPay result = "+data.getStringExtra(MOLPayActivity.MOLPayTransactionResult)); TextView tw = (TextView)findViewById(R.id.resultTV); @@ -65,18 +109,27 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); - } -// @Override -// public boolean onOptionsItemSelected(MenuItem item) { -// int id = item.getItemId(); -// -// if (id == R.id.action_settings) { -// return true; -// } -// -// return super.onOptionsItemSelected(item); -// } + // The Google Pay button is a layout file – take the root view + googlePayButton = findViewById(R.id.googlePayButton); + + try { + // TODO: Choose your preferred Google Pay button : https://developers.google.com/pay/api/android/guides/brand-guidelines + googlePayButton.initialize( + ButtonOptions.newBuilder() + .setButtonTheme(ButtonConstants.ButtonTheme.DARK) + .setButtonType(ButtonConstants.ButtonType.PAY) + .setCornerRadius(99) + .setAllowedPaymentMethods(UtilGP.getAllowedPaymentMethods().toString()) + .build() + ); + googlePayButton.setOnClickListener(view -> { + googlePayPayment(); + }); + } catch (JSONException e) { + // Keep Google Pay button hidden (consider logging this to your app analytics service) + } + } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -89,7 +142,7 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); - // closebtn clicked + // START clicked if (id == R.id.newBtn) { restartmolpay(); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8d97f9e..0f47482 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,8 +13,9 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - android:background="?attr/colorPrimary" - app:popupTheme="@style/AppTheme.PopupOverlay"> + android:background="#0038a3" + app:titleTextColor="@color/white" + app:subtitleTextColor="@color/white"> diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index f7224bd..1acdbc1 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -16,5 +16,13 @@ android:id="@+id/resultTV" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Hello World!" /> + android:text="Tap Google Pay button or START for other payments" /> + + + diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index bf5d905..79b7769 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -2,11 +2,6 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.molpay.molpayxdkproject.MainActivity"> - #3F51B5 #303F9F #FF4081 + #FFFFFF diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7728142..f9c1a19 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,4 @@ - RazerMSXDKProject - Settings + Fiuu XDK Android Start diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 545b9c6..8d367f1 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -6,6 +6,7 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent + #00d600