This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2213703
commit 9cab508
Showing
41 changed files
with
1,233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.DS_Store | ||
*.gradle | ||
*.iml | ||
|
||
PaymentApp/.externalNativeBuild | ||
PaymentApp/.idea/libraries | ||
PaymentApp/.idea/workspace.xml | ||
|
||
PaymentApp/build | ||
PaymentApp/captures | ||
PaymentApp/local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/krystosterone/Library/Android/sdk/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 |
26 changes: 26 additions & 0 deletions
26
PaymentApp/app/src/androidTest/java/com/shopify/paymentapp/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.shopify.paymentapp; | ||
|
||
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 <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.shopify.paymentapp", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.shopify.paymentapp"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".HomeActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".PaymentActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="org.chromium.intent.action.PAY" /> | ||
</intent-filter> | ||
<meta-data | ||
android:name="org.chromium.default_payment_method_name" | ||
android:value="interledger" /> | ||
</activity> | ||
</application> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
</manifest> |
22 changes: 22 additions & 0 deletions
22
PaymentApp/app/src/main/java/com/shopify/paymentapp/Credentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.shopify.paymentapp; | ||
|
||
/** | ||
* Created by krystosterone on 2017-06-07. | ||
*/ | ||
|
||
public enum Credentials { | ||
LEDGER_URL("https://red.ilpdemo.org"), | ||
LEDGER_ILP("[email protected]"), | ||
LEDGER_AUTH_TOKEN("YWxpY2U6YWxpY2U="); // base64(alice:alice) | ||
|
||
private final String value; | ||
|
||
Credentials(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
PaymentApp/app/src/main/java/com/shopify/paymentapp/HomeActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.shopify.paymentapp; | ||
|
||
import android.content.pm.PackageInfo; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Formatter; | ||
|
||
public class HomeActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_home); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
PaymentApp/app/src/main/java/com/shopify/paymentapp/JsonRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.shopify.paymentapp; | ||
|
||
import com.google.gson.FieldNamingPolicy; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by krystosterone on 2017-06-07. | ||
*/ | ||
|
||
public class JsonRequest<T> { | ||
private final String url; | ||
private final String requestMethod; | ||
private final JSONObject payload; | ||
private final Map<String, String> requestHeaders; | ||
|
||
public JsonRequest(String url, String requestMethod) { | ||
this(url, requestMethod, null, null); | ||
} | ||
|
||
public JsonRequest(String url, String requestMethod, JSONObject payload, Map<String, String> requestHeaders) { | ||
this.url = url; | ||
this.requestMethod = requestMethod; | ||
this.payload = payload; | ||
this.requestHeaders = requestHeaders; | ||
} | ||
|
||
public T execute(Class<T> responseClass) throws IOException { | ||
URL url = new URL(this.url); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestMethod(this.requestMethod); | ||
connection.setRequestProperty("Content-Type", "application/json"); | ||
|
||
if (requestHeaders != null) { | ||
for (Map.Entry<String, String> entry : this.requestHeaders.entrySet()) { | ||
connection.setRequestProperty(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
|
||
if (this.payload != null) { | ||
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); | ||
writer.write(this.payload.toString()); | ||
writer.flush(); | ||
} | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
stringBuilder.append(line + "\n"); | ||
} | ||
reader.close(); | ||
|
||
return new Gson().fromJson(stringBuilder.toString(), responseClass); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
PaymentApp/app/src/main/java/com/shopify/paymentapp/Payment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.shopify.paymentapp; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.annotations.Expose; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Created by krystosterone on 2017-06-02. | ||
*/ | ||
|
||
public class Payment { | ||
private final UUID uuid; | ||
private final String spspEndpoint; | ||
private final double totalAmount; | ||
private final Quote.Response quoteResponse; | ||
|
||
public Payment(UUID uuid, String spspEndpoint, double totalAmount, Quote.Response quoteResponse) { | ||
this.uuid = uuid; | ||
this.spspEndpoint = spspEndpoint; | ||
this.totalAmount = totalAmount; | ||
this.quoteResponse = quoteResponse; | ||
} | ||
|
||
// See: https://github.com/interledgerjs/ilp-kit/blob/3079862314f4433e974d14d56b65eafd374fbf5f/api/src/lib/pay.js#L44 | ||
public Response execute() throws IOException, JSONException { | ||
// It this really the way we should resolve the Quoting and Payments API URLs? | ||
// Should we have done a webfinger request to get those? | ||
// See: https://interledger.org/rfcs/0009-simple-payment-setup-protocol/#appendix-a-optional-webfinger-discovery | ||
String url = Credentials.LEDGER_URL + "/api/payments/" + this.uuid; | ||
|
||
JSONObject destination = new JSONObject(); | ||
// This is not a real spspEndpoint | ||
// PaymentRequest is actually passing a destination user address | ||
// This is because of how the ilp-kit was implemented | ||
destination.put("identifier", this.spspEndpoint); | ||
|
||
JSONObject payload = new JSONObject(); | ||
payload.put("destination", destination); | ||
payload.put("quote", new JSONObject(new Gson().toJson(this.quoteResponse))); | ||
|
||
HashMap<String, String> requestHeaders = new HashMap<String, String>(); | ||
requestHeaders.put("Authorization", "Basic " + Credentials.LEDGER_AUTH_TOKEN); | ||
|
||
return new JsonRequest<Response>(url, "PUT", payload, requestHeaders).execute(Response.class); | ||
} | ||
|
||
public class Response { | ||
@Expose | ||
public Destination destination; | ||
|
||
@Expose | ||
public Quote.Response quote; | ||
|
||
public class Destination { | ||
@Expose | ||
public String identifier; | ||
} | ||
} | ||
} |
Oops, something went wrong.