Skip to content

Commit

Permalink
feat: add push provisioning methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Jan 22, 2024
1 parent 5466515 commit 5589ba7
Show file tree
Hide file tree
Showing 8 changed files with 1,470 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,28 @@ class Stripe {

/// check if a particular card can be provisioned with the current app
/// on this particular device.
///
/// This method is deprecated. Use [canAddCardToWallet] instead.
@Deprecated('Use [canAddCardToWallet] instead')
Future<AddToWalletResult> canAddToWallet(String last4) async {
return await _platform.canAddToWallet(last4);
}

/// check if a particular card can be provisioned with the current app
/// on this particular device.
/// Throws [StripeException] in case creating the token fails.
Future<CanAddCardToWalletResult> canAddCardToWallet(
CanAddCardToWalletParams params) async {
return await _platform.canAddCardToWallet(params);
}

/// check if a particular card can be provisioned with the current app
/// on this particular device.
/// Throws [StripeException] in case creating the token fails.
Future<IsCardInWalletResult> isCardInWallet(String cardLastFour) async {
return await _platform.isCardInWallet(cardLastFour);
}

/// Call the financial connections authentication flow in order to collect a US bank account to enhance payouts.
///
/// Needs `clientSecret` of the stripe financial connections sessions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:stripe_platform_interface/src/models/financial_connections.dart'
import 'package:stripe_platform_interface/src/models/google_pay.dart';
import 'package:stripe_platform_interface/src/models/intent_creation_callback_params.dart';
import 'package:stripe_platform_interface/src/models/platform_pay.dart';
import 'package:stripe_platform_interface/src/models/push_provisioning.dart';
import 'package:stripe_platform_interface/src/models/wallet.dart';
import 'package:stripe_platform_interface/src/result_parser.dart';

Expand Down Expand Up @@ -630,6 +631,29 @@ class MethodChannelStripe extends StripePlatform {
{'params': params.toJson()},
);
}

@override
Future<CanAddCardToWalletResult> canAddCardToWallet(
CanAddCardToWalletParams params) async {
final result = await _methodChannel.invokeMethod('canAddCardToWallet', {
'params': params.toJson(),
});

return ResultParser<CanAddCardToWalletResult>(
parseJson: (json) => CanAddCardToWalletResult.fromJson(json))
.parse(result: result!, successResultKey: 'canAddCardToWalletResult');
}

@override
Future<IsCardInWalletResult> isCardInWallet(String cardLastFour) async {
final result = await _methodChannel.invokeMethod('canAddCardToWallet', {
'params': {'cardLastFour': cardLastFour},
});

return ResultParser<IsCardInWalletResult>(
parseJson: (json) => IsCardInWalletResult.fromJson(json))
.parse(result: result!, successResultKey: 'canAddCardToWalletResult');
}
}

class MethodChannelStripeFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// ignore_for_file: constant_identifier_names

import 'package:freezed_annotation/freezed_annotation.dart';

part 'push_provisioning.freezed.dart';

Check warning on line 5 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

freezed

"freezed" is a typo. Did you mean "freezes"?
part 'push_provisioning.g.dart';

@freezed

Check warning on line 8 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

freezed

"freezed" is a typo. Did you mean "freezes"?

/// Tokenized token for Google Pay.
class GooglePayCardToken with _$GooglePayCardToken {
@JsonSerializable(explicitToJson: true)
const factory GooglePayCardToken({
/// The token reference ID.,
required String id,

/// Last four digits of the FPAN,
required String fpanLastFour,

Check warning on line 18 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

fpanLastFour

"fpanLastFour" is a typo. Did you mean "fanLastFour"?

/// Last four digits of the DPAN,
required String dpanLastFour,

Check warning on line 21 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

dpanLastFour

"dpanLastFour" is a typo. Did you mean "spanLastFour"?

/// The network of the card.
required int network,

/// The service provider of the card.
required int serviceProvider,

/// The name of the issuer.,
required String issuer,

/// The GooglePayCardTokenStatus.,
required GooglePayCardTokenStatus status,

/// Deprecated. Use fpanLastFour or dpanLastFour.,

Check warning on line 35 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

dpanLastFour

"dpanLastFour" is a typo. Did you mean "spanLastFour"?

Check warning on line 35 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

fpanLastFour

"fpanLastFour" is a typo. Did you mean "fanLastFour"?
required String cardLastFour,
}) = _GooglePayCardToken;

factory GooglePayCardToken.fromJson(Map<String, dynamic> json) =>
_$GooglePayCardTokenFromJson(json);
}

@freezed

Check warning on line 43 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

freezed

"freezed" is a typo. Did you mean "freezes"?

/// The result of checking if a card is in the wallet.
class IsCardInWalletResult with _$IsCardInWalletResult {
@JsonSerializable(explicitToJson: true)
const factory IsCardInWalletResult({
required bool isInWallet,
GooglePayCardToken? token,
}) = _IsCardInWalletResult;

factory IsCardInWalletResult.fromJson(Map<String, dynamic> json) =>
_$IsCardInWalletResultFromJson(json);
}

@freezed

Check warning on line 57 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

freezed

"freezed" is a typo. Did you mean "freezes"?

/// The result of checking if a card can be added to the wallet.
class CanAddCardToWalletResult with _$CanAddCardToWalletResult {
@JsonSerializable(explicitToJson: true)
const factory CanAddCardToWalletResult({
required bool canAddCard,
CanAddCardToDetails? details,
}) = _CanAddCardToWalletResult;

factory CanAddCardToWalletResult.fromJson(Map<String, dynamic> json) =>
_$CanAddCardToWalletResultFromJson(json);
}

@freezed

Check warning on line 71 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

freezed

"freezed" is a typo. Did you mean "freezes"?

/// The details if card can be added.
class CanAddCardToDetails with _$CanAddCardToDetails {
@JsonSerializable(explicitToJson: true)
const factory CanAddCardToDetails({
GooglePayCardToken? token,
CanAddCardToWalletStatus? status,
}) = _CanAddCardToDetails;

factory CanAddCardToDetails.fromJson(Map<String, dynamic> json) =>
_$CanAddCardToDetailsFromJson(json);
}

@freezed

Check warning on line 85 in packages/stripe_platform_interface/lib/src/models/push_provisioning.dart

View workflow job for this annotation

GitHub Actions / Typo CI

freezed

"freezed" is a typo. Did you mean "freezes"?

/// The params for checking if a card is in the wallet.
class CanAddCardToWalletParams with _$CanAddCardToWalletParams {
@JsonSerializable(explicitToJson: true)
const factory CanAddCardToWalletParams({
///The `primary_account_identifier` value from the issued card. Can be an empty string.
String? primaryAccountIdentifier,

/// Last 4 digits of the card number. Required for Android.
required String cardLastFour,

/// iOS only. Set this to `true` until shipping through TestFlight || App Store. If false, you must be using live cards, and have the proper iOS entitlement set up. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#requesting-access-for-ios
bool? testEnv,

/// iOS only. Set this to `true` if: your user has an Apple Watch device currently paired, and you want to check that device for the presence of the specified card.
bool? hasPairedAppleWatch,

/// Android only, defaults to `true`. Set this to `false` if you'd like to allow users without NFC-enabled devices to add cards to the wallet. NFC is required for paying in stores.
bool? supportsTapToPay,
}) = _CanAddCardToWalletParams;

factory CanAddCardToWalletParams.fromJson(Map<String, dynamic> json) =>
_$CanAddCardToWalletParamsFromJson(json);
}

/// The google pay card token status.
enum GooglePayCardTokenStatus {
/// The token needs identity verification
TOKEN_STATE_NEEDS_IDENTITY_VERIFICATION,

/// The token is pending
TOKEN_STATE_PENDING,

/// The token is suspended
TOKEN_STATE_SUSPENDED,

/// The token is active
TOKEN_STATE_ACTIVE,

/// The token is pending provisioning
TOKEN_STATE_FELICA_PENDING_PROVISIONING,

/// The token is unprovisioned
TOKEN_STATE_UNTOKENIZED,
}

/// The can add card to wallet status.
enum CanAddCardToWalletStatus {
/// You are missing configuration required for Push Provisioning. Make sure you've completed all steps
MISSING_CONFIGURATION,

/// This device doesn't support adding a card to the native wallet.
UNSUPPORTED_DEVICE,

/// This card already exists on this device and any paired devices.
CARD_ALREADY_EXISTS,

/// This card already exists on this device, but not on the paired device.
CARD_EXISTS_ON_CURRENT_DEVICE,

/// This card already exists on the paired device, but not on this device.
CARD_EXISTS_ON_PAIRED_DEVICE,
}
Loading

0 comments on commit 5589ba7

Please sign in to comment.