为什么Stripe返回parameter_missing - success_url?

问题描述 投票:0回答:1

我对 Stripe checkout 进行了后期调用。我传递了多个 line_items,因为它来自购物车。但是每次触发调用时,Stripe 都会返回丢失的成功 url,即使我通过了它。当我查看 Stripe 仪表板中的日志时,我发现请求正文只是空的。但主体在 DevTools 中有数据。所以我真的不知道我做错了什么。我认为问题不在于缺少成功网址,而在于我认为更多关于列表的分配?

Here is the payload in DevTools:

我有一个数据类型为 winkelmandItemTypeSlijterij 的列表。代码的作用是将该列表格式化为 Stripe 期望的列表。

这是代码:

我尝试将列表格式化为 Stripe 期望的格式,但没有成功

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/actions/actions.dart' as action_blocks;
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'dart:convert';

import 'package:http/http.dart' as http;

Future<String> nogEenStripe(
    List<WinkelmandItemTypeSlijterijStruct> winkelmandList) async {
  // Add your function code here!

  List<Map<String, dynamic>> aangepasteLijst = [];

  for (var item in winkelmandList) {
    aangepasteLijst.add({
      'price_data': {
        'price_data': {
          'product': 'prod_${item.product}'
        } // Formatteer productnaam
      },
      'quantity': item.aantal,
    });
  }

  // Maak de formuliergegevens aan
  Map<String, dynamic> formData = {
    'mode': 'payment',
    'line_items': aangepasteLijst,
    'success_url': "https://example.com/success",
    'cancel_url': "https://example.com/cancel",
  };

  // Voer de HTTP-postaanvraag uit naar de Stripe Checkout API
  final response = await http.post(
    Uri.parse('https://api.stripe.com/v1/checkout/sessions'),
    headers: {
      'Authorization':
         'Bearer xxxxxxx',
      'Content-Type':
          'application/json', // Content-Type gewijzigd naar 'application/json'
    },
    body: jsonEncode(
        formData), // Formuliergegevens worden nu als JSON-gecodeerd verzonden
  );

  // Controleer of de aanvraag succesvol was
  if (response.statusCode == 200) {
    // Retourneer de sessie-ID uit de Stripe Checkout API-response
    return jsonDecode(response.body)['id'];
  } else {
    // Retourneer een foutmelding als er een probleem was met de aanvraag
    throw Exception('Failed to create checkout session');
  }
}
dart post stripe-payments flutterflow
1个回答
0
投票

您请求的产品不是 Stripe 产品。产品 ID (prod_xxx) 应从 Stripe Products API 创建。

此外,请求中的

unit_amount
拼写错误。您的代码显示
unit_amout
n
中缺少
amount

我建议根据 Checkout Session 集成文档检查您的请求,以确保您设置正确的请求参数及其值:https://docs.stripe.com/ payments/accept-a- payment?platform=web&ui=条纹托管

您还可以在仪表板https://dashboard.stripe.com/test/logs中找到请求日志,以检查系统已发送的错误和请求。

© www.soinside.com 2019 - 2024. All rights reserved.