Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 9cab508

Browse files
committed
Commit initial implementation
1 parent 2213703 commit 9cab508

Some content is hidden

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

41 files changed

+1233
-1
lines changed

.gitignore

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

PaymentApp/app/.gitignore

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

PaymentApp/app/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/krystosterone/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.shopify.paymentapp;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.shopify.paymentapp", appContext.getPackageName());
25+
}
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.shopify.paymentapp">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".HomeActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
<activity
20+
android:name=".PaymentActivity"
21+
android:exported="true">
22+
<intent-filter>
23+
<action android:name="org.chromium.intent.action.PAY" />
24+
</intent-filter>
25+
<meta-data
26+
android:name="org.chromium.default_payment_method_name"
27+
android:value="interledger" />
28+
</activity>
29+
</application>
30+
<uses-permission android:name="android.permission.INTERNET"/>
31+
</manifest>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.shopify.paymentapp;
2+
3+
/**
4+
* Created by krystosterone on 2017-06-07.
5+
*/
6+
7+
public enum Credentials {
8+
LEDGER_URL("https://red.ilpdemo.org"),
9+
LEDGER_ILP("[email protected]"),
10+
LEDGER_AUTH_TOKEN("YWxpY2U6YWxpY2U="); // base64(alice:alice)
11+
12+
private final String value;
13+
14+
Credentials(String value) {
15+
this.value = value;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return value;
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.shopify.paymentapp;
2+
3+
import android.content.pm.PackageInfo;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.util.Log;
7+
8+
import java.security.MessageDigest;
9+
import java.security.NoSuchAlgorithmException;
10+
import java.util.Formatter;
11+
12+
public class HomeActivity extends AppCompatActivity {
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_home);
18+
}
19+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.shopify.paymentapp;
2+
3+
import com.google.gson.FieldNamingPolicy;
4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
6+
7+
import org.json.JSONObject;
8+
9+
import java.io.BufferedReader;
10+
import java.io.IOException;
11+
import java.io.InputStreamReader;
12+
import java.io.OutputStreamWriter;
13+
import java.net.HttpURLConnection;
14+
import java.net.URL;
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
18+
/**
19+
* Created by krystosterone on 2017-06-07.
20+
*/
21+
22+
public class JsonRequest<T> {
23+
private final String url;
24+
private final String requestMethod;
25+
private final JSONObject payload;
26+
private final Map<String, String> requestHeaders;
27+
28+
public JsonRequest(String url, String requestMethod) {
29+
this(url, requestMethod, null, null);
30+
}
31+
32+
public JsonRequest(String url, String requestMethod, JSONObject payload, Map<String, String> requestHeaders) {
33+
this.url = url;
34+
this.requestMethod = requestMethod;
35+
this.payload = payload;
36+
this.requestHeaders = requestHeaders;
37+
}
38+
39+
public T execute(Class<T> responseClass) throws IOException {
40+
URL url = new URL(this.url);
41+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
42+
connection.setRequestMethod(this.requestMethod);
43+
connection.setRequestProperty("Content-Type", "application/json");
44+
45+
if (requestHeaders != null) {
46+
for (Map.Entry<String, String> entry : this.requestHeaders.entrySet()) {
47+
connection.setRequestProperty(entry.getKey(), entry.getValue());
48+
}
49+
}
50+
51+
if (this.payload != null) {
52+
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
53+
writer.write(this.payload.toString());
54+
writer.flush();
55+
}
56+
57+
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
58+
StringBuilder stringBuilder = new StringBuilder();
59+
String line;
60+
while ((line = reader.readLine()) != null) {
61+
stringBuilder.append(line + "\n");
62+
}
63+
reader.close();
64+
65+
return new Gson().fromJson(stringBuilder.toString(), responseClass);
66+
}
67+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.shopify.paymentapp;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.annotations.Expose;
5+
6+
import org.json.JSONException;
7+
import org.json.JSONObject;
8+
9+
import java.io.BufferedReader;
10+
import java.io.IOException;
11+
import java.io.InputStreamReader;
12+
import java.io.OutputStreamWriter;
13+
import java.net.HttpURLConnection;
14+
import java.net.URL;
15+
import java.util.HashMap;
16+
import java.util.UUID;
17+
18+
/**
19+
* Created by krystosterone on 2017-06-02.
20+
*/
21+
22+
public class Payment {
23+
private final UUID uuid;
24+
private final String spspEndpoint;
25+
private final double totalAmount;
26+
private final Quote.Response quoteResponse;
27+
28+
public Payment(UUID uuid, String spspEndpoint, double totalAmount, Quote.Response quoteResponse) {
29+
this.uuid = uuid;
30+
this.spspEndpoint = spspEndpoint;
31+
this.totalAmount = totalAmount;
32+
this.quoteResponse = quoteResponse;
33+
}
34+
35+
// See: https://github.com/interledgerjs/ilp-kit/blob/3079862314f4433e974d14d56b65eafd374fbf5f/api/src/lib/pay.js#L44
36+
public Response execute() throws IOException, JSONException {
37+
// It this really the way we should resolve the Quoting and Payments API URLs?
38+
// Should we have done a webfinger request to get those?
39+
// See: https://interledger.org/rfcs/0009-simple-payment-setup-protocol/#appendix-a-optional-webfinger-discovery
40+
String url = Credentials.LEDGER_URL + "/api/payments/" + this.uuid;
41+
42+
JSONObject destination = new JSONObject();
43+
// This is not a real spspEndpoint
44+
// PaymentRequest is actually passing a destination user address
45+
// This is because of how the ilp-kit was implemented
46+
destination.put("identifier", this.spspEndpoint);
47+
48+
JSONObject payload = new JSONObject();
49+
payload.put("destination", destination);
50+
payload.put("quote", new JSONObject(new Gson().toJson(this.quoteResponse)));
51+
52+
HashMap<String, String> requestHeaders = new HashMap<String, String>();
53+
requestHeaders.put("Authorization", "Basic " + Credentials.LEDGER_AUTH_TOKEN);
54+
55+
return new JsonRequest<Response>(url, "PUT", payload, requestHeaders).execute(Response.class);
56+
}
57+
58+
public class Response {
59+
@Expose
60+
public Destination destination;
61+
62+
@Expose
63+
public Quote.Response quote;
64+
65+
public class Destination {
66+
@Expose
67+
public String identifier;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)