Skip to content

Commit 6c8ec4f

Browse files
authored
Giropay integration update (#169)
1 parent 3d582c5 commit 6c8ec4f

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44
## UNRELEASED
55
### Added
66
### Changed
7+
* ui: Re-enable Giropay integration (#169)
8+
79
### Removed
810
### Fixed
911

ui/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
<uses-permission android:name="android.permission.VIBRATE" />
1010

11+
<queries>
12+
<package android:name="com.gimb.paydirekt.app" />
13+
<package android:name="com.gimb.paydirekt.app.sandbox" />
14+
</queries>
15+
1116
<application>
1217
<activity
1318
android:name=".checkout.CheckoutActivity"

ui/src/main/java/io/snabble/sdk/ui/payment/GiropayInputView.java

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.app.Activity;
55
import android.app.Application;
66
import android.content.Context;
7+
import android.content.Intent;
8+
import android.content.pm.ResolveInfo;
79
import android.net.Uri;
810
import android.os.Build;
911
import android.util.AttributeSet;
@@ -19,10 +21,14 @@
1921

2022
import androidx.activity.ComponentActivity;
2123
import androidx.activity.OnBackPressedCallback;
24+
import androidx.annotation.NonNull;
25+
import androidx.annotation.Nullable;
2226

27+
import java.util.List;
2328
import java.util.Map;
2429
import java.util.UUID;
2530

31+
import io.snabble.sdk.Environment;
2632
import io.snabble.sdk.Snabble;
2733
import io.snabble.sdk.payment.PaymentCredentials;
2834
import io.snabble.sdk.payment.data.GiropayAuthorizationData;
@@ -122,10 +128,18 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
122128

123129
@Override
124130
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
125-
Uri uri = request.getUrl();
126-
if (uri != null) {
127-
String url = uri.toString();
128-
Logger.d("shouldOverrideUrlLoading " + url);
131+
final Uri uri = request.getUrl();
132+
final Environment environment = Snabble.getInstance().getEnvironment();
133+
if (isGiropayAppLinkUrl(uri, environment)) {
134+
final Intent giropayAppLinkIntent = new Intent(Intent.ACTION_VIEW);
135+
giropayAppLinkIntent.setData(request.getUrl());
136+
if (isGiropayAppAvailable(giropayAppLinkIntent, view.getContext(), environment)) {
137+
view.getContext().startActivity(giropayAppLinkIntent);
138+
return true;
139+
}
140+
} else if (uri != null) {
141+
final String url = uri.toString();
142+
Logger.d("shouldOverrideUrlLoading: <" + url + ">");
129143

130144
switch (url) {
131145
case SUCCESS_URL:
@@ -216,6 +230,46 @@ public void error(Throwable t) {
216230
});
217231
}
218232

233+
private boolean isGiropayAppLinkUrl(@Nullable final Uri uri, @Nullable Environment environment) {
234+
if (uri != null && uri.getHost() != null) {
235+
return uri.getHost().startsWith(getGiropayAppLinkUrlHost(environment));
236+
}
237+
return false;
238+
}
239+
240+
@NonNull
241+
private String getGiropayAppLinkUrlHost(@Nullable final Environment environment) {
242+
if (environment == Environment.PRODUCTION) {
243+
return "app.paydirekt.de";
244+
} else {
245+
return "app.sandbox.paydirekt.de";
246+
}
247+
}
248+
249+
private boolean isGiropayAppAvailable(
250+
@NonNull final Intent intent,
251+
@NonNull final Context context,
252+
@Nullable final Environment environment
253+
) {
254+
final List<ResolveInfo> intentInfo = context.getPackageManager().queryIntentActivities(intent, 0);
255+
final String appPackageName = getGiropayAppPackage(environment);
256+
for (final ResolveInfo info : intentInfo) {
257+
if (info.activityInfo.packageName.contains(appPackageName)) {
258+
return true;
259+
}
260+
}
261+
return false;
262+
}
263+
264+
@NonNull
265+
private String getGiropayAppPackage(final @Nullable Environment environment) {
266+
if (environment == Environment.PRODUCTION) {
267+
return "com.gimb.paydirekt.app";
268+
} else {
269+
return "com.gimb.paydirekt.app.sandbox";
270+
}
271+
}
272+
219273
private void authenticateAndSave() {
220274
Keyguard.unlock(UIUtils.getHostFragmentActivity(getContext()), new Keyguard.Callback() {
221275
@Override

0 commit comments

Comments
 (0)