Skip to content

Commit

Permalink
feat: finish deffered callback flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Aug 28, 2023
1 parent 2c6dc90 commit 91bf823
Show file tree
Hide file tree
Showing 7 changed files with 2,270 additions and 2,492 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,27 @@ class _PaymentSheetScreenState extends State<PaymentSheetDefferedScreen> {
);
}

Future<void> _createIntentAndConfirmToUser() async {
final url = Uri.parse('$kApiUrl/payment-sheet');
Future<void> _createIntentAndConfirmToUser(String paymentMethodId) async {
print('foo $paymentMethodId');
final url = Uri.parse('$kApiUrl/payment-intent-for-payment-sheet');
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
},
body: json.encode({
'a': 'a',
'paymentMethodId': paymentMethodId,
}),
);
final body = json.decode(response.body);
if (body['error'] != null) {
throw Exception(body['error']);
}

print('blaat $body');

await Stripe.instance.intentCreationCallback(
IntentCreationCallbackParams(clientSecret: body['paymentIntent']));
IntentCreationCallbackParams(clientSecret: body['clientSecret']));
}

Future<void> initPaymentSheet() async {
Expand Down Expand Up @@ -96,8 +99,8 @@ class _PaymentSheetScreenState extends State<PaymentSheetDefferedScreen> {
currencyCode: 'EUR',
amount: 1500,
),
intentCreationCallback: (method, saveFuture) {
_createIntentAndConfirmToUser();
confirmHandler: (method, saveFuture) {
_createIntentAndConfirmToUser(method.id);
}),

// Extra params
Expand All @@ -109,6 +112,7 @@ class _PaymentSheetScreenState extends State<PaymentSheetDefferedScreen> {
merchantCountryCode: 'DE',
testEnv: true,
),

style: ThemeMode.dark,
appearance: PaymentSheetAppearance(
colors: PaymentSheetAppearanceColors(
Expand Down
24 changes: 12 additions & 12 deletions example/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.9.6",
"@babel/runtime": "^7.9.6",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.2",
"@types/jest": "^26.0.14",
"@types/node": "^12.7.2",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"babel-plugin-module-resolver": "^4.0.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"express": "^4.17.3",
"husky": "^4.2.3",
"nodemon": "^1.19.1",
"onchange": "^6.1.0",
"cors": "^2.8.5",
"path": "^0.12.7",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"run-script-os": "^1.1.1",
"stripe": "^13.1.0",
"ts-node": "^8.3.0",
"typescript": "^4.0.3",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.9.6",
"@babel/runtime": "^7.9.6",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.2",
"babel-plugin-module-resolver": "^4.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.3",
"path": "^0.12.7",
"stripe": "^10.14.0"
"typescript": "^4.0.3"
},
"dependencies": {
"@types/cors": "^2.8.12",
Expand Down
Loading

0 comments on commit 91bf823

Please sign in to comment.