Skip to content

Commit 5e84d93

Browse files
Merge pull request #12 from TapPay/chris/migrate_to_android_x_and_sdk_3.6.0
Chris/migrate to android x and sdk 3.6.0
2 parents 59a769f + d5ba777 commit 5e84d93

File tree

65 files changed

+1638
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1638
-55
lines changed

AtomePayExample/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

AtomePayExample/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

AtomePayExample/app/build.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdk 31
7+
8+
defaultConfig {
9+
applicationId "tech.cherri.atomepayexample"
10+
minSdk 18
11+
targetSdk 31
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
}
29+
30+
dependencies {
31+
32+
implementation 'androidx.appcompat:appcompat:1.4.1'
33+
implementation 'com.google.android.material:material:1.5.0'
34+
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
35+
implementation files('libs/tpdirect.aar')
36+
testImplementation 'junit:junit:4.+'
37+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
38+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
39+
}

AtomePayExample/app/libs/tpdirect.aar

406 KB
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package tech.cherri.atomepayexample;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("tech.cherri.atomepayexample", appContext.getPackageName());
25+
}
26+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="tech.cherri.atomepayexample">
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
tools:replace="android:allowBackup"
13+
android:theme="@style/Theme.AtomePayExample">
14+
<activity
15+
android:name=".MainActivity"
16+
android:exported="true">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
<intent-filter android:autoVerify="true">
23+
<action android:name="android.intent.action.VIEW" />
24+
25+
<category android:name="android.intent.category.DEFAULT" />
26+
<category android:name="android.intent.category.BROWSABLE" />
27+
28+
<data
29+
android:scheme="https"
30+
android:host="example.com"
31+
android:pathPrefix="/test" />
32+
33+
<data
34+
android:scheme="atomeexample"
35+
android:host="atome.app"
36+
android:pathPrefix="/test" />
37+
38+
</intent-filter>
39+
<intent-filter android:autoVerify="true">
40+
<action android:name="android.intent.action.VIEW" />
41+
42+
<category android:name="android.intent.category.DEFAULT" />
43+
<category android:name="android.intent.category.BROWSABLE" />
44+
45+
<data
46+
android:scheme="https"
47+
android:host="example.com"
48+
android:pathPrefix="/test" />
49+
50+
<data
51+
android:scheme="atomeexample"
52+
android:host="atome.app"
53+
android:pathPrefix="/test" />
54+
</intent-filter>
55+
</activity>
56+
</application>
57+
<queries>
58+
<!-- for atome pay open -->
59+
<package android:name="tw.atome.paylater" />
60+
</queries>
61+
</manifest>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package tech.cherri.atomepayexample;
2+
3+
import android.content.Context;
4+
import android.os.AsyncTask;
5+
6+
import tech.cherri.tpdirect.utils.SDKLog;
7+
8+
public class ApiUtil {
9+
public static void callAtomePayByPrime(
10+
Context context, String prime, String itemId,
11+
String itemName, String itemQuantity, String itemPrice, ResultListener listener) {
12+
13+
SDKLog.d("ApiUtil", "callAtomePayByPrimeWithMiddleServer, prime =" + prime);
14+
String details = "[{\"item_id\": \"" + itemId
15+
+ "\",\"item_name\": \"" + itemName
16+
+ " \",\"item_quantity\":" + itemQuantity
17+
+ ",\"item_price\":" + itemPrice + "}]";
18+
19+
AtomePayByPrimeTask atomePayByPrimeTask = new AtomePayByPrimeTask(
20+
context, prime, details, listener);
21+
22+
23+
atomePayByPrimeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
24+
25+
}
26+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package tech.cherri.atomepayexample;
2+
3+
import android.content.Context;
4+
import android.os.AsyncTask;
5+
6+
import androidx.annotation.NonNull;
7+
8+
import org.json.JSONException;
9+
import org.json.JSONObject;
10+
11+
import java.io.BufferedReader;
12+
import java.io.IOException;
13+
import java.io.InputStreamReader;
14+
import java.io.OutputStreamWriter;
15+
import java.net.HttpURLConnection;
16+
import java.net.URL;
17+
18+
import tech.cherri.tpdirect.utils.SDKLog;
19+
20+
public class AtomePayByPrimeTask extends AsyncTask<String, Void, JSONObject> {
21+
private final String prime;
22+
private final ResultListener listener;
23+
private final String details;
24+
private JSONObject jsonRequest;
25+
private JSONObject extraInfo;
26+
private JSONObject shopperInfo;
27+
private JSONObject shippingAddress;
28+
private JSONObject billingAddress;
29+
private JSONObject resultUrl;
30+
private JSONObject cardHolder;
31+
private String targetUrl;
32+
33+
public AtomePayByPrimeTask(Context context, String prime, String details, ResultListener listener) {
34+
this.prime = prime;
35+
this.details = details;
36+
this.listener = listener;
37+
this.targetUrl = Constants.TAPPAY_DOMAIN + Constants.TAPPAY_PAY_BY_PRIME_URL;
38+
39+
jsonRequest = new JSONObject();
40+
extraInfo = new JSONObject();
41+
shopperInfo = new JSONObject();
42+
shippingAddress = new JSONObject();
43+
billingAddress = new JSONObject();
44+
resultUrl = new JSONObject();
45+
cardHolder = new JSONObject();
46+
47+
try {
48+
shippingAddress.put("country_code", "TW");
49+
shippingAddress.put("lines", "台北市中正區羅斯福路100號六樓");
50+
shippingAddress.put("postcode", "100");
51+
52+
billingAddress.put("country_code", "TW");
53+
billingAddress.put("lines", "台北市中正區羅斯福路100號六樓");
54+
billingAddress.put("postcode", "100");
55+
56+
shopperInfo.put("shipping_address", shippingAddress);
57+
shopperInfo.put("billing_address", billingAddress);
58+
extraInfo.put("shopper_info", shopperInfo);
59+
60+
resultUrl.put("frontend_redirect_url", Constants.FRONTEND_REDIRECT_URL_EXAMPLE);
61+
resultUrl.put("backend_notify_url", Constants.BACKEND_NOTIFY_URL_EXAMPLE);
62+
63+
cardHolder.put("phone_number", "+8860932123456");
64+
cardHolder.put("name", "test");
65+
cardHolder.put("email", "test@gmail.com");
66+
67+
jsonRequest.put("prime", prime);
68+
jsonRequest.put("partner_key", Constants.PARTNER_KEY);
69+
jsonRequest.put("merchant_id", Constants.MERCHANT_ID);
70+
jsonRequest.put("amount", 50);
71+
jsonRequest.put("details", this.details);
72+
jsonRequest.put("extra_info", extraInfo);
73+
jsonRequest.put("result_url", resultUrl);
74+
jsonRequest.put("cardholder", cardHolder);
75+
76+
} catch (JSONException e) {
77+
e.printStackTrace();
78+
}
79+
}
80+
81+
@Override
82+
protected JSONObject doInBackground(String... strings) {
83+
JSONObject outputJSONObj = new JSONObject();
84+
85+
try {
86+
HttpURLConnection connection = prepareHttpURLConnection();
87+
writeRequestTo(connection);
88+
89+
int HttpResult = connection.getResponseCode();
90+
SDKLog.d("test", "HttpResult = " + HttpResult);
91+
92+
String HttpMsgResult = connection.getResponseMessage();
93+
SDKLog.d("test", "HttpMsgResult = " + HttpMsgResult);
94+
95+
96+
String responseStr = getResponseString(connection);
97+
SDKLog.d("test", "response = " + responseStr);
98+
99+
outputJSONObj = new JSONObject(responseStr); // Get entity
100+
} catch (Exception e) {
101+
e.printStackTrace();
102+
outputJSONObj = new JSONObject();
103+
try {
104+
outputJSONObj.put("status", -1);
105+
outputJSONObj.put("exception", e.toString());
106+
} catch (JSONException jsonException) {
107+
jsonException.printStackTrace();
108+
}
109+
}
110+
return outputJSONObj;
111+
}
112+
113+
@Override
114+
protected void onPostExecute(JSONObject jsonObject) {
115+
116+
try {
117+
int status = jsonObject.getInt("status");
118+
switch (status) {
119+
case 0:
120+
listener.onTaskSuccess(jsonObject);
121+
break;
122+
case -1:
123+
String exceptionString = jsonObject.getString("exception");
124+
listener.onTaskFailed(exceptionString);
125+
break;
126+
default:
127+
listener.onTaskFailed(jsonObject.toString());
128+
}
129+
} catch (Exception e) {
130+
listener.onTaskFailed(e.toString());
131+
e.printStackTrace();
132+
}
133+
134+
}
135+
136+
@NonNull
137+
private HttpURLConnection prepareHttpURLConnection() throws IOException {
138+
URL url = new URL(targetUrl);
139+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
140+
connection.setConnectTimeout(40000);
141+
connection.setReadTimeout(30000);
142+
connection.setRequestProperty("Content-Type", "application/json");
143+
connection.setRequestProperty("x-api-key", Constants.PARTNER_KEY);
144+
connection.setRequestMethod("POST");
145+
return connection;
146+
}
147+
148+
private void writeRequestTo(HttpURLConnection connection) throws IOException {
149+
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
150+
wr.write(jsonRequest.toString());
151+
SDKLog.d("test", "request = " + jsonRequest.toString());
152+
wr.flush();
153+
wr.close();
154+
}
155+
156+
@NonNull
157+
private String getResponseString(HttpURLConnection connection) throws IOException {
158+
BufferedReader br = new BufferedReader(
159+
new InputStreamReader(connection.getInputStream(), "utf-8"));
160+
StringBuilder responseStr = new StringBuilder("");
161+
String line = "";
162+
163+
while ((line = br.readLine()) != null) {
164+
responseStr.append(line);
165+
}
166+
br.close();
167+
return responseStr.toString();
168+
}
169+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package tech.cherri.atomepayexample;
2+
3+
import tech.cherri.tpdirect.api.TPDServerType;
4+
5+
public class Constants {
6+
public static final TPDServerType SERVER_TYPE = TPDServerType.Sandbox;
7+
8+
public static final String TAPPAY_DOMAIN = "https://sandbox.tappaysdk.com/tpc";
9+
10+
public static final String TAPPAY_PAY_BY_PRIME_URL = "/payment/pay-by-prime";
11+
public static final String FRONTEND_REDIRECT_URL_EXAMPLE = "https://example.com/front-end-redirect";
12+
public static final String BACKEND_NOTIFY_URL_EXAMPLE = "https://example.com/back-end-notify";
13+
14+
public static final String PARTNER_KEY = "your partner key";
15+
public static final String APP_KEY = "your app key";
16+
public static final Integer APP_ID = 0; // your app id
17+
18+
public static final String MERCHANT_ID = "your merchant id";
19+
20+
public static final String RETURN_URL = "atomepayexample://atome.app/test"; // for intents
21+
}

0 commit comments

Comments
 (0)