Commit 285191ce authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[WebLayer] payment_request_spec becomes ground truth of PaymentOptions

This CL allows PaymentRequestSpec to provide the PaymentOptions that
is saved in payment_request_spec.

Bug: 1148936

Change-Id: I05451f4d76f759b6aad9b3c1c893901789e0f805
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537058
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827643}
parent a29ec537
...@@ -55,9 +55,18 @@ public class PaymentRequestSpec { ...@@ -55,9 +55,18 @@ public class PaymentRequestSpec {
return mNativePointer == 0; return mNativePointer == 0;
} }
/**
* @return The payment options specified by the merchant. This method cannot be used after the
* instance is destroyed.
*/
public PaymentOptions getPaymentOptions() {
return PaymentOptions.deserialize(
ByteBuffer.wrap(PaymentRequestSpecJni.get().getPaymentOptions(mNativePointer)));
}
/** /**
* @return The map of supported payment method identifiers and corresponding payment * @return The map of supported payment method identifiers and corresponding payment
* method specific data. This value is still available after the instance is destroyed. * method specific data. This method cannot be used after the instance is destroyed.
*/ */
public Map<String, PaymentMethodData> getMethodData() { public Map<String, PaymentMethodData> getMethodData() {
Map<String, PaymentMethodData> methodDataMap = new ArrayMap<>(); Map<String, PaymentMethodData> methodDataMap = new ArrayMap<>();
...@@ -74,7 +83,7 @@ public class PaymentRequestSpec { ...@@ -74,7 +83,7 @@ public class PaymentRequestSpec {
/** /**
* A mapping from method names to modifiers, which include modified totals and additional line * A mapping from method names to modifiers, which include modified totals and additional line
* items. Used to display modified totals for each payment apps, modified total in order * items. Used to display modified totals for each payment apps, modified total in order
* summary, and additional line items in order summary. This value is still available after the * summary, and additional line items in order summary. This method cannot be used after the
* instance is destroyed. * instance is destroyed.
*/ */
public Map<String, PaymentDetailsModifier> getModifiers() { public Map<String, PaymentDetailsModifier> getModifiers() {
...@@ -91,8 +100,8 @@ public class PaymentRequestSpec { ...@@ -91,8 +100,8 @@ public class PaymentRequestSpec {
} }
/** /**
* @return The id of the request, found in PaymentDetails. This value is still available after * @return The id of the request, found in PaymentDetails. This method cannot be used after the
* the instance is destroyed. * instance is destroyed.
*/ */
public String getId() { public String getId() {
return getPaymentDetails().id; return getPaymentDetails().id;
...@@ -100,8 +109,8 @@ public class PaymentRequestSpec { ...@@ -100,8 +109,8 @@ public class PaymentRequestSpec {
/** /**
* The raw shipping options, as it was received from the website. This data is passed to the * The raw shipping options, as it was received from the website. This data is passed to the
* payment app when the app is responsible for handling shipping address. This value is still * payment app when the app is responsible for handling shipping address. This method cannot be
* available after the instance is destroyed. * used after the instance is destroyed.
*/ */
public List<PaymentShippingOption> getRawShippingOptions() { public List<PaymentShippingOption> getRawShippingOptions() {
PaymentDetails details = getPaymentDetails(); PaymentDetails details = getPaymentDetails();
...@@ -112,7 +121,7 @@ public class PaymentRequestSpec { ...@@ -112,7 +121,7 @@ public class PaymentRequestSpec {
/** /**
* The raw items in the shopping cart, as they were received from the website. This data is * The raw items in the shopping cart, as they were received from the website. This data is
* passed to the payment app. This value is still available after the instance is destroyed. * passed to the payment app. This method cannot be used after the instance is destroyed.
*/ */
public List<PaymentItem> getRawLineItems() { public List<PaymentItem> getRawLineItems() {
PaymentDetails details = getPaymentDetails(); PaymentDetails details = getPaymentDetails();
...@@ -123,13 +132,16 @@ public class PaymentRequestSpec { ...@@ -123,13 +132,16 @@ public class PaymentRequestSpec {
/** /**
* The raw total amount being charged, as it was received from the website. This data is passed * The raw total amount being charged, as it was received from the website. This data is passed
* to the payment app. This value is still available after the instance is destroyed. * to the payment app. This method cannot be used after the instance is destroyed.
*/ */
public PaymentItem getRawTotal() { public PaymentItem getRawTotal() {
return getPaymentDetails().total; return getPaymentDetails().total;
} }
/** @return The payment details specified in the payment request. */ /**
* @return The payment details specified in the payment request. This method cannot be used
* after the instance is destroyed.
*/
public PaymentDetails getPaymentDetails() { public PaymentDetails getPaymentDetails() {
return PaymentDetails.deserialize( return PaymentDetails.deserialize(
ByteBuffer.wrap(PaymentRequestSpecJni.get().getPaymentDetails(mNativePointer))); ByteBuffer.wrap(PaymentRequestSpecJni.get().getPaymentDetails(mNativePointer)));
...@@ -192,5 +204,6 @@ public class PaymentRequestSpec { ...@@ -192,5 +204,6 @@ public class PaymentRequestSpec {
void destroy(long nativePaymentRequestSpec); void destroy(long nativePaymentRequestSpec);
byte[] getPaymentDetails(long nativePaymentRequestSpec); byte[] getPaymentDetails(long nativePaymentRequestSpec);
byte[][] getMethodData(long nativePaymentRequestSpec); byte[][] getMethodData(long nativePaymentRequestSpec);
byte[] getPaymentOptions(long nativePaymentRequestSpec);
} }
} }
...@@ -97,6 +97,12 @@ PaymentRequestSpec::GetPaymentDetails(JNIEnv* env) { ...@@ -97,6 +97,12 @@ PaymentRequestSpec::GetPaymentDetails(JNIEnv* env) {
env, mojom::PaymentDetails::Serialize(&spec_->details_ptr())); env, mojom::PaymentDetails::Serialize(&spec_->details_ptr()));
} }
base::android::ScopedJavaLocalRef<jbyteArray>
PaymentRequestSpec::GetPaymentOptions(JNIEnv* env) {
return base::android::ToJavaByteArray(
env, mojom::PaymentOptions::Serialize(&spec_->payment_options()));
}
base::android::ScopedJavaLocalRef<jobjectArray> base::android::ScopedJavaLocalRef<jobjectArray>
PaymentRequestSpec::GetMethodData(JNIEnv* env) { PaymentRequestSpec::GetMethodData(JNIEnv* env) {
return SerializeToJavaArrayOfByteArrays(env, spec_->method_data()); return SerializeToJavaArrayOfByteArrays(env, spec_->method_data());
......
...@@ -61,6 +61,9 @@ class PaymentRequestSpec { ...@@ -61,6 +61,9 @@ class PaymentRequestSpec {
// Returns the payment details. // Returns the payment details.
base::android::ScopedJavaLocalRef<jbyteArray> GetPaymentDetails(JNIEnv* env); base::android::ScopedJavaLocalRef<jbyteArray> GetPaymentDetails(JNIEnv* env);
// Returns the payment options.
base::android::ScopedJavaLocalRef<jbyteArray> GetPaymentOptions(JNIEnv* env);
// Returns the method data. // Returns the method data.
base::android::ScopedJavaLocalRef<jobjectArray> GetMethodData(JNIEnv* env); base::android::ScopedJavaLocalRef<jobjectArray> GetMethodData(JNIEnv* env);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment