Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
## UNRELEASED
### Added
### Changed
* ui: Re-enable Giropay integration (#169)

### Removed
### Fixed

Expand Down
5 changes: 5 additions & 0 deletions ui/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

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

<queries>
<package android:name="com.gimb.paydirekt.app" />
<package android:name="com.gimb.paydirekt.app.sandbox" />
</queries>

<application>
<activity
android:name=".checkout.CheckoutActivity"
Expand Down
62 changes: 58 additions & 4 deletions ui/src/main/java/io/snabble/sdk/ui/payment/GiropayInputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.util.AttributeSet;
Expand All @@ -19,10 +21,14 @@

import androidx.activity.ComponentActivity;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import io.snabble.sdk.Environment;
import io.snabble.sdk.Snabble;
import io.snabble.sdk.payment.PaymentCredentials;
import io.snabble.sdk.payment.data.GiropayAuthorizationData;
Expand Down Expand Up @@ -122,10 +128,18 @@ public void onReceivedError(WebView view, int errorCode, String description, Str

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri uri = request.getUrl();
if (uri != null) {
String url = uri.toString();
Logger.d("shouldOverrideUrlLoading " + url);
final Uri uri = request.getUrl();
final Environment environment = Snabble.getInstance().getEnvironment();
if (isGiropayAppLinkUrl(uri, environment)) {
final Intent giropayAppLinkIntent = new Intent(Intent.ACTION_VIEW);
giropayAppLinkIntent.setData(request.getUrl());
if (isGiropayAppAvailable(giropayAppLinkIntent, view.getContext(), environment)) {
view.getContext().startActivity(giropayAppLinkIntent);
return true;
}
} else if (uri != null) {
final String url = uri.toString();
Logger.d("shouldOverrideUrlLoading: <" + url + ">");

switch (url) {
case SUCCESS_URL:
Expand Down Expand Up @@ -216,6 +230,46 @@ public void error(Throwable t) {
});
}

private boolean isGiropayAppLinkUrl(@Nullable final Uri uri, @Nullable Environment environment) {
if (uri != null && uri.getHost() != null) {
return uri.getHost().startsWith(getGiropayAppLinkUrlHost(environment));
}
return false;
}

@NonNull
private String getGiropayAppLinkUrlHost(@Nullable final Environment environment) {
if (environment == Environment.PRODUCTION) {
return "app.paydirekt.de";
} else {
return "app.sandbox.paydirekt.de";
}
}

private boolean isGiropayAppAvailable(
@NonNull final Intent intent,
@NonNull final Context context,
@Nullable final Environment environment
) {
final List<ResolveInfo> intentInfo = context.getPackageManager().queryIntentActivities(intent, 0);
final String appPackageName = getGiropayAppPackage(environment);
for (final ResolveInfo info : intentInfo) {
if (info.activityInfo.packageName.contains(appPackageName)) {
return true;
}
}
return false;
}

@NonNull
private String getGiropayAppPackage(final @Nullable Environment environment) {
if (environment == Environment.PRODUCTION) {
return "com.gimb.paydirekt.app";
} else {
return "com.gimb.paydirekt.app.sandbox";
}
}

private void authenticateAndSave() {
Keyguard.unlock(UIUtils.getHostFragmentActivity(getContext()), new Keyguard.Callback() {
@Override
Expand Down