Wallet: Add dummy for isReadyToPay() API

This commit is contained in:
Marvin W 2020-11-19 16:53:50 +01:00
parent d038fd82cf
commit 9ef9f29940
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A
7 changed files with 334 additions and 1 deletions

View File

@ -0,0 +1,3 @@
package com.google.android.gms.wallet;
parcelable IsReadyToPayRequest;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<Integer> allowedCardNetworks;
@Field(4)
private String unknown4;
@Field(5)
private String unknown5;
@Field(6)
private ArrayList<Integer> 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.
* <p>
* To convert back to a JSON object serialized as string use {@link #toJson()}.
* <p>
* 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.
* <p>
* For the expected format of this JSON, please see <a href="https://developers.google.com/pay/api/android/reference/object/IsReadyToPayRequest">IsReadyToPayRequest object reference documentation</a>.
*/
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.
* <p>
* Note that this will be {@code null} if this request was not constructed using {@link #fromJson(String)}.
* <p>
* For the expected format of this JSON, please see <a href="https://developers.google.com/pay/api/android/reference/object/IsReadyToPayRequest">IsReadyToPayRequest object reference documentation</a>.
*/
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<Integer> 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<Integer> 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<Integer> 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<Integer> 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.
* <p>
* 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<IsReadyToPayRequest> CREATOR = new AutoCreator<>(IsReadyToPayRequest.class);
}

View File

@ -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<IsReadyToPayResponse> CREATOR = new AutoCreator<>(IsReadyToPayResponse.class);
}

View File

@ -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.
* <p>
* Available options:
* <ul>
* <li>{@link #CARD_NETWORK_AMEX}</li>
* <li>{@link #CARD_NETWORK_DISCOVER}</li>
* <li>{@link #CARD_NETWORK_JCB}</li>
* <li>{@link #CARD_NETWORK_MASTERCARD}</li>
* <li>{@link #CARD_NETWORK_VISA}</li>
* <li>{@link #CARD_NETWORK_INTERAC}</li>
* <li>{@link #CARD_NETWORK_OTHER}</li>
* </ul>
* When used with Google Pay, the following networks use EMV cryptograms instead of 3DS cryptograms as part of the payment credentials:
* <ul>
* <li>{@link #CARD_NETWORK_INTERAC}</li>
* </ul>
*/
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.
* <p>
* Available options:
* <ul>
* <li>{@link #PAYMENT_METHOD_UNKNOWN}</li>
* <li>{@link #PAYMENT_METHOD_CARD}</li>
* <li>{@link #PAYMENT_METHOD_TOKENIZED_CARD}</li>
* </ul>
* 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.
* <p>
* Available options:
* <ul>
* <li>{@link #PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY}</li>
* <li>{@link #PAYMENT_METHOD_TOKENIZATION_TYPE_NETWORK_TOKEN}</li>
* <li>{@link #PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT}</li>
* </ul>
* 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;
}

View File

@ -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