diff --git a/play-services-api/src/main/aidl/com/google/android/gms/wallet/IsReadyToPayRequest.aidl b/play-services-api/src/main/aidl/com/google/android/gms/wallet/IsReadyToPayRequest.aidl new file mode 100644 index 00000000..da1b0344 --- /dev/null +++ b/play-services-api/src/main/aidl/com/google/android/gms/wallet/IsReadyToPayRequest.aidl @@ -0,0 +1,3 @@ +package com.google.android.gms.wallet; + +parcelable IsReadyToPayRequest; diff --git a/play-services-api/src/main/aidl/com/google/android/gms/wallet/internal/IOwService.aidl b/play-services-api/src/main/aidl/com/google/android/gms/wallet/internal/IOwService.aidl index d9cb9209..ae55cffb 100644 --- a/play-services-api/src/main/aidl/com/google/android/gms/wallet/internal/IOwService.aidl +++ b/play-services-api/src/main/aidl/com/google/android/gms/wallet/internal/IOwService.aidl @@ -1,5 +1,8 @@ package com.google.android.gms.wallet.internal; -interface IOwService { +import com.google.android.gms.wallet.internal.IWalletServiceCallbacks; +import com.google.android.gms.wallet.IsReadyToPayRequest; +interface IOwService { + void isReadyToPay(in IsReadyToPayRequest request, in Bundle args, IWalletServiceCallbacks callbacks) = 13; } diff --git a/play-services-api/src/main/aidl/com/google/android/gms/wallet/internal/IWalletServiceCallbacks.aidl b/play-services-api/src/main/aidl/com/google/android/gms/wallet/internal/IWalletServiceCallbacks.aidl new file mode 100644 index 00000000..aae5209f --- /dev/null +++ b/play-services-api/src/main/aidl/com/google/android/gms/wallet/internal/IWalletServiceCallbacks.aidl @@ -0,0 +1,7 @@ +package com.google.android.gms.wallet.internal; + +import com.google.android.gms.common.api.Status; + +interface IWalletServiceCallbacks { + void onIsReadyToPayResponse(in Status status, boolean result, in Bundle args) = 8; +} diff --git a/play-services-api/src/main/java/com/google/android/gms/wallet/IsReadyToPayRequest.java b/play-services-api/src/main/java/com/google/android/gms/wallet/IsReadyToPayRequest.java new file mode 100644 index 00000000..5af03541 --- /dev/null +++ b/play-services-api/src/main/java/com/google/android/gms/wallet/IsReadyToPayRequest.java @@ -0,0 +1,161 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0 + * Notice: Portions of this file are reproduced from work created and shared by Google and used + * according to terms described in the Creative Commons 4.0 Attribution License. + * See https://developers.google.com/readme/policies for details. + */ + +package com.google.android.gms.wallet; + +import org.microg.gms.common.PublicApi; +import org.microg.safeparcel.AutoSafeParcelable; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * A Parcelable request that can optionally be passed to {@link PaymentsClient#isReadyToPay(IsReadyToPayRequest)} to specify additional filtering criteria for determining if a user is considered ready to pay. + */ +@PublicApi +public class IsReadyToPayRequest extends AutoSafeParcelable { + @Field(2) + private ArrayList allowedCardNetworks; + @Field(4) + private String unknown4; + @Field(5) + private String unknown5; + @Field(6) + private ArrayList allowedPaymentMethods; + @Field(7) + private boolean existingPaymentMethodRequired; + @Field(8) + private String json; + + private IsReadyToPayRequest() { + } + + private IsReadyToPayRequest(String json) { + this.json = json; + } + + /** + * Constructs {@link IsReadyToPayRequest} from a JSON object serialized as a string. + *

+ * To convert back to a JSON object serialized as string use {@link #toJson()}. + *

+ * Note that you shouldn't rely on the values returned by getters in {@link IsReadyToPayRequest} as they will not be populated with the data set in the given JSON. + *

+ * For the expected format of this JSON, please see IsReadyToPayRequest object reference documentation. + */ + public static IsReadyToPayRequest fromJson(String isReadyToPayRequestJson) { + return new IsReadyToPayRequest(isReadyToPayRequestJson); + } + + /** + * @return a builder for constructing the {@link IsReadyToPayRequest} object. + * @deprecated Use the JSON request format instead, see {@link #fromJson(String)}. + */ + public static IsReadyToPayRequest.Builder newBuilder() { + return new IsReadyToPayRequest().new Builder(); + } + + /** + * Returns {@link IsReadyToPayRequest} in JSON format. + *

+ * Note that this will be {@code null} if this request was not constructed using {@link #fromJson(String)}. + *

+ * For the expected format of this JSON, please see IsReadyToPayRequest object reference documentation. + */ + public String toJson() { + return json; + } + + /** + * @return the {@link WalletConstants.CardNetwork} that will be used to filter the instruments deemed acceptable by {@link PaymentsClient#isReadyToPay(IsReadyToPayRequest)}. If not explicitly set, the default supported networks will be {@link WalletConstants#CARD_NETWORK_AMEX}, {@link WalletConstants#CARD_NETWORK_DISCOVER}, {@link WalletConstants#CARD_NETWORK_MASTERCARD}, and {@link WalletConstants#CARD_NETWORK_VISA}. + * @deprecated Use the JSON request format instead, see {@link #fromJson(String)}. + */ + public ArrayList getAllowedCardNetworks() { + return allowedCardNetworks; + } + + /** + * @return the supported payment credential types defined in {@link WalletConstants.PaymentMethod}, or {@code null} if no restrictions were specified. + * @deprecated Use the JSON request format instead, see {@link #fromJson(String)}. + */ + public ArrayList getAllowedPaymentMethods() { + return allowedPaymentMethods; + } + + /** + * @return whether or not IsReadyToPay will be determined by the user having an existing payment method that matches the other criteria specified in the IsReadyToPayRequest. + * @deprecated Use the JSON request format instead, see {@link #fromJson(String)}. + */ + public boolean isExistingPaymentMethodRequired() { + return existingPaymentMethodRequired; + } + + /** + * Builder for creating an {@link IsReadyToPayRequest}. + * + * @deprecated Use the JSON request format instead, see {@link #fromJson(String)}. + */ + public class Builder { + /** + * Adds a card network for cards allowed in the purchase. See {@link WalletConstants.CardNetwork} for available options. If not explicitly set via this or {@link #addAllowedCardNetworks(Collection)}, the default supported networks will be {@link WalletConstants#CARD_NETWORK_AMEX}, {@link WalletConstants#CARD_NETWORK_DISCOVER}, {@link WalletConstants#CARD_NETWORK_MASTERCARD}, and {@link WalletConstants#CARD_NETWORK_VISA}. + */ + public Builder addAllowedCardNetwork(int allowedCardNetwork) { + if (allowedCardNetworks == null) allowedCardNetworks = new ArrayList<>(); + allowedCardNetworks.add(allowedCardNetwork); + return this; + } + + /** + * Adds a collection of card networks for cards allowed in the purchase. See {@link WalletConstants.CardNetwork} for available options. If not explicitly set via this or {@link #addAllowedCardNetwork(int)}, the default supported networks will be {@link WalletConstants#CARD_NETWORK_AMEX}, {@link WalletConstants#CARD_NETWORK_DISCOVER}, {@link WalletConstants#CARD_NETWORK_MASTERCARD}, and {@link WalletConstants#CARD_NETWORK_VISA}. + */ + public Builder addAllowedCardNetworks(Collection allowedCardNetworks) { + if (IsReadyToPayRequest.this.allowedCardNetworks == null) + IsReadyToPayRequest.this.allowedCardNetworks = new ArrayList<>(); + IsReadyToPayRequest.this.allowedCardNetworks.addAll(allowedCardNetworks); + return this; + } + + /** + * Adds an allowed payment method. See {@link WalletConstants.PaymentMethod} for available options. If not explicitly set via this or {@link #addAllowedPaymentMethods(Collection)}, then the default allowed payment method will be {@link WalletConstants#PAYMENT_METHOD_TOKENIZED_CARD}. + */ + public Builder addAllowedPaymentMethod(int allowedPaymentMethod) { + if (allowedPaymentMethods == null) allowedPaymentMethods = new ArrayList<>(); + allowedPaymentMethods.add(allowedPaymentMethod); + return this; + } + + /** + * Adds a collection of allowed payment methods. See {@link WalletConstants.PaymentMethod} for available options. If not explicitly set via this or {@link #addAllowedPaymentMethod(int)}, then the default allowed payment method will be {@link WalletConstants#PAYMENT_METHOD_TOKENIZED_CARD}. + */ + public Builder addAllowedPaymentMethods(Collection allowedPaymentMethods) { + if (IsReadyToPayRequest.this.allowedPaymentMethods == null) + IsReadyToPayRequest.this.allowedPaymentMethods = new ArrayList<>(); + IsReadyToPayRequest.this.allowedPaymentMethods.addAll(allowedPaymentMethods); + return this; + } + + /** + * @return The actual {@link IsReadyToPayRequest} created using the data passed to the Builder object. + */ + public IsReadyToPayRequest build() { + return IsReadyToPayRequest.this; + } + + /** + * If set to true, then IsReadyToPay will only return true if the user has an existing payment method that matches the other criteria specified in the IsReadyToPayRequest. + *

+ * If you set this to true, make sure to call {@link PaymentsClient#isReadyToPay(IsReadyToPayRequest)} as early as possible in your flow as the call may take longer to resolve due to the extra check for an existing payment method. + */ + public Builder setExistingPaymentMethodRequired(boolean existingPaymentMethodRequired) { + IsReadyToPayRequest.this.existingPaymentMethodRequired = existingPaymentMethodRequired; + return this; + } + } + + public static final Creator CREATOR = new AutoCreator<>(IsReadyToPayRequest.class); +} diff --git a/play-services-api/src/main/java/com/google/android/gms/wallet/IsReadyToPayResponse.java b/play-services-api/src/main/java/com/google/android/gms/wallet/IsReadyToPayResponse.java new file mode 100644 index 00000000..96b02404 --- /dev/null +++ b/play-services-api/src/main/java/com/google/android/gms/wallet/IsReadyToPayResponse.java @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.wallet; + +import org.microg.safeparcel.AutoSafeParcelable; + +public class IsReadyToPayResponse extends AutoSafeParcelable { + @Field(1) + public boolean result; + @Field(2) + public String json; + + private IsReadyToPayResponse() { + } + + public IsReadyToPayResponse(boolean result, String json) { + this.result = result; + this.json = json; + } + + public static final Creator CREATOR = new AutoCreator<>(IsReadyToPayResponse.class); +} diff --git a/play-services-api/src/main/java/com/google/android/gms/wallet/WalletConstants.java b/play-services-api/src/main/java/com/google/android/gms/wallet/WalletConstants.java new file mode 100644 index 00000000..0e3e2056 --- /dev/null +++ b/play-services-api/src/main/java/com/google/android/gms/wallet/WalletConstants.java @@ -0,0 +1,117 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 AND CC-BY-4.0 + * Notice: Portions of this file are reproduced from work created and shared by Google and used + * according to terms described in the Creative Commons 4.0 Attribution License. + * See https://developers.google.com/readme/policies for details. + */ + +package com.google.android.gms.wallet; + +import org.microg.gms.common.PublicApi; + +/** + * Collection of constant values used by the ClientLibrary. + */ +@PublicApi +public class WalletConstants { + /** + * Credit card networks. Different APIs may support only a subset of these. + *

+ * Available options: + *

+ * When used with Google Pay, the following networks use EMV cryptograms instead of 3DS cryptograms as part of the payment credentials: + * + */ + public @interface CardNetwork { + /** + * @deprecated Use {@link #CARD_NETWORK_AMEX} instead. + */ + int AMEX = 1; + /** + * @deprecated Use {@link #CARD_NETWORK_DISCOVER} instead. + */ + int DISCOVER = 2; + /** + * @deprecated Use {@link #CARD_NETWORK_JCB} instead. + */ + int JCB = 3; + /** + * @deprecated Use {@link #CARD_NETWORK_MASTERCARD} instead. + */ + int MASTERCARD = 4; + /** + * @deprecated Use {@link #CARD_NETWORK_VISA} instead. + */ + int VISA = 5; + /** + * @deprecated Use {@link #CARD_NETWORK_INTERAC} instead. + */ + int INTERAC = 6; + /** + * @deprecated Use {@link #CARD_NETWORK_OTHER} instead. + */ + int OTHER = 1000; + } + + /** + * The payment methods you support. + *

+ * Available options: + *

+ * Note {@link WalletConstants.PaymentMethod} is different from {@link PaymentMethodTokenizationType}, which identifies how you want to receive the returned payment credential. + */ + public @interface PaymentMethod { + } + + /** + * Payment method tokenization types. + *

+ * Available options: + *

+ * Integrator can configure {@link PaymentDataRequest} to tokenize the credit card selected by the buyer for a transaction using one of the tokenization types listed above. The token for the selected payment method can be retrieved by calling {@link PaymentData#getPaymentMethodToken()}. + */ + public @interface PaymentMethodTokenizationType { + } + + + public static final int CARD_CLASS_CREDIT = 1; + public static final int CARD_CLASS_DEBIT = 2; + public static final int CARD_CLASS_PREPAID = 3; + public static final int CARD_CLASS_UNKNOWN = 0; + + public static final int CARD_NETWORK_AMEX = 1; + public static final int CARD_NETWORK_DISCOVER = 2; + public static final int CARD_NETWORK_INTERAC = 6; + public static final int CARD_NETWORK_JCB = 3; + public static final int CARD_NETWORK_MASTERCARD = 4; + public static final int CARD_NETWORK_OTHER = 1000; + public static final int CARD_NETWORK_VISA = 5; + + public static final int PAYMENT_METHOD_CARD = 1; + public static final int PAYMENT_METHOD_TOKENIZED_CARD = 2; + public static final int PAYMENT_METHOD_UNKNOWN = 0; + + + public static final int PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT = 3; + public static final int PAYMENT_METHOD_TOKENIZATION_TYPE_NETWORK_TOKEN = 2; + public static final int PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY = 1; +} diff --git a/play-services-core/src/main/java/org/microg/gms/wallet/OwServiceImpl.java b/play-services-core/src/main/java/org/microg/gms/wallet/OwServiceImpl.java index ad38eb08..3ab6de1f 100644 --- a/play-services-core/src/main/java/org/microg/gms/wallet/OwServiceImpl.java +++ b/play-services-core/src/main/java/org/microg/gms/wallet/OwServiceImpl.java @@ -17,16 +17,33 @@ package org.microg.gms.wallet; import android.content.Context; +import android.os.Bundle; +import android.os.Handler; import android.os.Parcel; import android.os.RemoteException; import android.util.Log; +import com.google.android.gms.common.api.Status; +import com.google.android.gms.wallet.IsReadyToPayRequest; import com.google.android.gms.wallet.internal.IOwService; +import com.google.android.gms.wallet.internal.IWalletServiceCallbacks; public class OwServiceImpl extends IOwService.Stub { private static final String TAG = "GmsWalletOwSvc"; + private Context context; public OwServiceImpl(Context context) { + this.context = context; + } + + @Override + public void isReadyToPay(IsReadyToPayRequest request, Bundle args, IWalletServiceCallbacks callbacks) throws RemoteException { + Log.d(TAG, "isReadyToPay: " + request.toJson()); + try { + callbacks.onIsReadyToPayResponse(Status.SUCCESS, false, Bundle.EMPTY); + } catch (Exception e) { + Log.w(TAG, e); + } } @Override