Skip to content

Commit

Permalink
Sync (#1015)
Browse files Browse the repository at this point in the history
* Android: Sync with React Native v0.20.0

* Sync iOS with React Native v0.20.0

* resetPaymentSheetCustomer for iOS

* fix integration tests

* add missing type

* increase timeout for github action

* sync dart layer

* BREAKING add onDidSetShippingContact to presentapplepay

* add onDidSetShippingMethod callback for handling shipping methods

* chore: add changelog, increase version

Co-authored-by: Remon <[email protected]>
  • Loading branch information
jonasbark and remonh87 authored Nov 15, 2022
1 parent 9b64d8b commit 7866c4d
Show file tree
Hide file tree
Showing 56 changed files with 2,041 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/all_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:

integration_test:
name: Integration test
timeout-minutes: 30
timeout-minutes: 60
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 2 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.7.0'
implementation 'com.google.android.gms:play-services-wallet:19.1.0'
implementation 'com.stripe:stripe-wechatpay:17.1.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BridgeTest {
@Test
fun testGetDouble() {
val map = ReadableMap(mapOf("test" to 1.1))
assert(map.getDouble("test") == 1.1)
assert(map.getDouble("test") == 1.1f)
}
@Test
fun testGetIntShouldFail() {
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '12.0'
platform :ios, '13.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
30 changes: 29 additions & 1 deletion example/lib/screens/wallets/apple_pay_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -50,16 +51,43 @@ class _ApplePayScreenState extends State<ApplePayScreen> {
try {
// 1. Present Apple Pay sheet
await Stripe.instance.presentApplePay(
ApplePayPresentParams(
params: ApplePayPresentParams(
cartItems: [
ApplePayCartSummaryItem.immediate(
label: 'Product Test',
amount: '0.01',
),
],
requiredShippingAddressFields: [
ApplePayContactFieldsType.postalAddress,
],
shippingMethods: [
ApplePayShippingMethod(
identifier: 'free',
detail: 'Arrives by July 2',
label: 'Free Shipping',
amount: '0.0',
),
ApplePayShippingMethod(
identifier: 'standard',
detail: 'Arrives by June 29',
label: 'Standard Shipping',
amount: '3.21',
),
],
country: 'Es',
currency: 'EUR',
),
onDidSetShippingContact: (contact) {
if (kDebugMode) {
print('shipping contact provided $contact ');
}
},
onDidSetShippingMethod: (method) {
if (kDebugMode) {
print('shipping method provided $method ');
}
},
);

// 2. fetch Intent Client Secret from backend
Expand Down
15 changes: 15 additions & 0 deletions packages/stripe/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 7.0.0
**Breaking Changes**
- This library now supports iOS 13 and up, due to stripe-ios increasing the deployment target

**Features**
- Added Link support in Payment Sheet.
- Added the resetPaymentSheetCustomer method to clear persisted authentication state in the PaymentSheet.
- Added preferredNetwork and availableNetworks fields to the CardResult payment method.
- Added support for custom fonts to CardForm and CardView on Android.
- Added support for customizing the call to action button label in Payment Sheet by providing the primaryButtonLabel property to initPaymentSheet().

- **Fixes**
- Several fixes by the Stripe sdk [v.0.20.0](https://github.com/stripe/stripe-react-native/releases/tag/v0.20.0).


## 6.0.0

**Breaking Changes**
Expand Down
28 changes: 20 additions & 8 deletions packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,22 @@ class Stripe {
/// configuration. See [ApplePayPresentParams] for more details.
///
/// Throws an [StripeError] in case presenting the payment sheet fails.
Future<void> presentApplePay(
ApplePayPresentParams params,
) async {
Future<void> presentApplePay({
required ApplePayPresentParams params,
OnDidSetShippingContact? onDidSetShippingContact,
OnDidSetShippingMethod? onDidSetShippingMethod,
}) async {
await _awaitForSettings();
if (!isApplePaySupported.value) {
//throw StripeError<ApplePayError>
//(ApplePayError.canceled, 'APPLE_PAY_NOT_SUPPORTED_MESSAGE');
}
try {
await _platform.presentApplePay(params);
await _platform.presentApplePay(
params,
onDidSetShippingContact,
onDidSetShippingMethod,
);
} on StripeError {
rethrow;
}
Expand Down Expand Up @@ -356,14 +362,20 @@ class Stripe {
/// See [PresentPaymentSheetPameters] for more details
///
/// throws [StripeException] in case of a failure
Future<void> presentPaymentSheet({
@Deprecated('Params are now inherited from initPaymentSheet so this `parameters` can be removed')
dynamic parameters,
}) async {
Future<void> presentPaymentSheet() async {
await _awaitForSettings();
return await _platform.presentPaymentSheet();
}

/// Call this method when the user logs out from your app.
///
/// This will ensur ethat any persisted authentication state in the
/// paymentsheet, such as authentication cookies are cleared during logout.
Future<void> resetPaymentSheetCustomer() async {
await _awaitForSettings();
return await _platform.resetPaymentSheetCustomer();
}

/// Confirms the paymentsheet payment
///
/// throws [StripeException] in case of a failure
Expand Down
8 changes: 4 additions & 4 deletions packages/stripe/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_stripe
description: Flutter library for Stripe. Supports PaymentSheets, Apple & Google Pay, SCA, PSD2 and much more.
version: 6.0.0
version: 7.0.0
homepage: https://github.com/flutter-stripe/flutter_stripe
repository: https://github.com/flutter-stripe/flutter_stripe

Expand All @@ -21,9 +21,9 @@ flutter:
dependencies:
flutter:
sdk: flutter
stripe_android: ^6.0.0
stripe_ios: ^6.0.0
stripe_platform_interface: ^6.0.0
stripe_android: ^7.0.0
stripe_ios: ^7.0.0
stripe_platform_interface: ^7.0.0
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
21 changes: 20 additions & 1 deletion packages/stripe_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
## 7.0.0
**Breaking Changes**
- This library now supports iOS 13 and up, due to stripe-ios increasing the deployment target

**Features**
- Added Link support in Payment Sheet.
- Added the resetPaymentSheetCustomer method to clear persisted authentication state in the PaymentSheet.
- Added preferredNetwork and availableNetworks fields to the CardResult payment method.
- Added support for custom fonts to CardForm and CardView on Android.
- Added support for customizing the call to action button label in Payment Sheet by providing the primaryButtonLabel property to initPaymentSheet().

- **Fixes**
- Several fixes by the Stripe sdk [v.0.20.0](https://github.com/stripe/stripe-react-native/releases/tag/v0.20.0).


## 6.0.0

** Breaking Changes **
**Breaking Changes**

- Move `PaymentMethodOptions` out of `PaymentMethodparams` so interface is similar with Stripe sdk.

Expand All @@ -18,6 +33,7 @@ await Stripe.instance.confirmPayment(
),
),
);
```

Now

Expand All @@ -42,6 +58,9 @@ await Stripe.instance.confirmPayment(
- Several fixes by the Stripe sdk [v.0.19.0](https://github.com/stripe/stripe-react-native/releases/tag/v0.19.0).
- Fix for #462, added `handleURLCallback` method for iOS to handle `returnUrl` when iDeal payment is successful. This will close the in-app webview of Safari.

## 5.0.1
- Fix for #462, added `handleURLCallback` method for iOS to handle `returnUrl` when iDeal payment is successful. This will close the in-app webview of Safari

## 5.0.0
Breaking changes
- Your compileSdkVersion (in android/build.gradle) now must be at least 32. Changing your compileSdkVersion does not change runtime behavior.
Expand Down
4 changes: 2 additions & 2 deletions packages/stripe_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
implementation 'com.stripe:stripe-android:20.12.+'
implementation "com.stripe:financial-connections:20.12.+"
implementation 'com.stripe:stripe-android:20.15.+'
implementation "com.stripe:financial-connections:20.15.+"
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ public ReadableArray(JSONArray array) {
this.array = array;
}

public String getString(int index) throws JSONException {
return array.getString(index);
public String getString(int index) {
try {
return array.getString(index);
} catch (JSONException e) {
return null;
}
}

public int getInt(int index) throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.uimanager;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;

/**
* Holds an instance of the current DisplayMetrics so we don't have to thread it through all the
* classes that need it.
*/
public class DisplayMetricsHolder {

private static @Nullable DisplayMetrics sWindowDisplayMetrics;
private static @Nullable DisplayMetrics sScreenDisplayMetrics;

public static void setWindowDisplayMetrics(DisplayMetrics displayMetrics) {
sWindowDisplayMetrics = displayMetrics;
}

public static void initDisplayMetricsIfNotInitialized(Context context) {
if (DisplayMetricsHolder.getScreenDisplayMetrics() != null) {
return;
}
initDisplayMetrics(context);
}

public static void initDisplayMetrics(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics);

DisplayMetrics screenDisplayMetrics = new DisplayMetrics();
screenDisplayMetrics.setTo(displayMetrics);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();

// Get the real display metrics if we are using API level 17 or higher.
// The real metrics include system decor elements (e.g. soft menu bar).
//
// See:
// http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics)
display.getRealMetrics(screenDisplayMetrics);
DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics);
}

/** Returns the metrics of the window associated to the Context used to initialize ReactNative */
public static DisplayMetrics getWindowDisplayMetrics() {
return sWindowDisplayMetrics;
}

public static void setScreenDisplayMetrics(DisplayMetrics screenDisplayMetrics) {
sScreenDisplayMetrics = screenDisplayMetrics;
}

/** Screen metrics returns the metrics of the default screen on the device. */
public static DisplayMetrics getScreenDisplayMetrics() {
return sScreenDisplayMetrics;
}

public static WritableMap getDisplayMetricsWritableMap(double fontScale) {
final WritableNativeMap result = new WritableNativeMap();
result.putMap(
"windowPhysicalPixels", getPhysicalPixelsWritableMap(sWindowDisplayMetrics, fontScale));
result.putMap(
"screenPhysicalPixels", getPhysicalPixelsWritableMap(sScreenDisplayMetrics, fontScale));
return result;
}

private static WritableMap getPhysicalPixelsWritableMap(
DisplayMetrics displayMetrics, double fontScale) {
final WritableNativeMap result = new WritableNativeMap();
result.putInt("width", displayMetrics.widthPixels);
result.putInt("height", displayMetrics.heightPixels);
result.putDouble("scale", displayMetrics.density);
result.putDouble("fontScale", fontScale);
result.putDouble("densityDpi", displayMetrics.densityDpi);
return result;
}
}
Loading

0 comments on commit 7866c4d

Please sign in to comment.