Flutter哥伦比亚支付插件wompi_payment_colombia的使用

发布于 1周前 作者 itying888 来自 Flutter

Flutter哥伦比亚支付插件wompi_payment_colombia的使用

标题

Flutter哥伦比亚支付插件wompi_payment_colombia的使用

内容

This README describes the package. If you publish this package to pub.dev, this README’s contents appear on the landing page for your package.

For information about how to write a good package README, see the guide for writing package pages.

For general information about developing packages, see the Dart guide for creating packages and the Flutter guide for developing packages and plugins.


Wompi Payment SDK - Colombia #

Disclaimer #</aa>

This is an unofficial implementation of the Wompi API, we are not responsible for bugs derived from its use. For additional information you can refer to the official Wompi documentation. <aa href="https://docs.wompi.co/" rel="ugc">https://docs.wompi.co/

Features #</h<>

[x] Credit Card Payments [x] Nequi Payments [x] PSE Payments

Usage #

import 'package:wompi_payment_colombia/src/src_exports.dart';

void main() async { // # Create a new instance of the WompiClient

WompiClient wompiClient = WompiClient( publicKey: ‘BusinessPublicKey’, // Business Public Key from Wompi Dashboard environment: Environment.PRODUCTION, // or Environment.TEST for testing purposes, businessPrefix: ‘FR-’, // Business Prefix integrityKey: ‘’, // secret integrity key from Wompi Dashboard currency: ‘COP’, // Currency for the payments );

// First you need to GET the acceptance token from the server, this is the token that will be used to make the payment. // The user must be explicitly accepted the terms and conditions of the payment. final acceptance = await WompiService.getAcceptance(wompiClient: wompiClient);

///Get the link to the PDF file with the terms. The user must be explicitly accepted the terms and conditions of the payment. // ignore: unused_local_variable final pdfTermsLink = acceptance.data.presignedAcceptance.permalink;

// Get the token from the server and use it to make the payment. final acceptanceToken = acceptance.data.presignedAcceptance.acceptanceToken;

// For every method you need to create an instance of the PaymentRequestData PaymentRequestData paymentRequestData = PaymentRequestData( email: “test@mail.com”, // The email of the user who will make the payment. phone: “1111111111”, // The phone of the user who will make the payment. name: “Customer Name”, // The name of the user who will make the payment. acceptanceToken: acceptanceToken, // The token that will be used to make the payment. reference: “payment_reference”, // The reference of the payment. document: “customer_identification” // The document of the user who will make the payment.

);

// *------------------ # MAKE A CREDIT CARD PAYMENT ------------------ *

CreditCard creditCard = CreditCard( cardNumber: “1111111111111111”, // Credit card number cvcCode: “123”, // CVC code expYear: “24”, // Expiration year expMonth: “12”, // Expiration month amount: 20000, // Amount to pay as integer quotas: 12, // Quotas to pay as integer cardHolder: “Customer Name” // Card holder name );

// Create instance fot Payment CreditCardPay creditCardPay = CreditCardPay( creditCard: creditCard, // Credit card information paymentRequest: paymentRequestData, // Payment request data wompiClient: wompiClient // Wompi client );

// Make the payment with the credit card information. final CardPaymentResponse cardPayment = await WompiService.pay(paymentProcessor: creditCardPay);

// Check the response of the payment. final CardCheckModel cardCheck = await WompiService.checkPayment( paymentChecker: CreditCardCheck( transactionId: cardPayment.data.id, wompiClient: wompiClient));

print(cardCheck.data.status);

// *------------------ # MAKE A NEQUI PAYMENT ------------------ *

NequiPay nequiPay = NequiPay( paymentRequest: paymentRequestData, // Payment request data wompiClient: wompiClient, // Wompi client amount: 25000, // Amount to pay as integer phoneNumberToPay: “1111111111” // Phone number to pay );

/// Make the payment with the Nequi information. final NequiPaymentResponse nequiPayment = await WompiService.pay(paymentProcessor: nequiPay);

// Check the response of the payment. final NequiCheckModel nequiCheck = await WompiService.checkPayment( paymentChecker: NequiCheck( transactionId: nequiPayment.data.id, wompiClient: wompiClient)); print(nequiCheck.data.status);

/// *------------------ # MAKE A PSE PAYMENT ------------------ *

// First you need to get the List of banks to allow the user to choose one. final banks = await WompiService.getBankss(wompiClient: wompiClient); final selectedBank = banks.first; // In this case the user select the first Bank.

// Create instance for the PSE Request final pseRequest = PseRequest( personType: PersonType.natural, // Person type documentType: “CC”, // Document type amount: 30000, // Amount to pay as integer bankCode: selectedBank.financialInstitutionCode, // Bank code paymentDescription: “Test Payment” // Payment description );

// Create the payment with the PSE information. final psePay = PsePay( pseRequest: pseRequest, // PSE request data paymentRequest: paymentRequestData, // Payment request data wompiClient: wompiClient // Wompi client );

// Make the payment with the PSE information. final PsePaymentResponse payment = await WompiService.pay(paymentProcessor: psePay);

// You need to redirect the user to the URL provided by the Wompi Service. // ignore: unused_local_variable final paymentURL = payment.data.paymentMethod.extra!.asyncPaymentUrl;

// Then you need to check the PSE payment status. final PsePaymentResponse response = await WompiService.checkPayment( paymentChecker: PseCheck(transactionId: payment.data.id, wompiClient: wompiClient));

print(response.data.status); }

Testing #</h<>

We have added an E2E tests section for verification of the services using the test sandbox. You can run them manually by cloning this repository, and checking in the tests/payment_methods/PAYMENT-METHOD/service_tests folder by modifying the related information in the TestUtils class.


示例代码


更多关于Flutter哥伦比亚支付插件wompi_payment_colombia的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter哥伦比亚支付插件wompi_payment_colombia的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


当然,以下是如何在Flutter应用中使用wompi_payment_colombia插件的一个示例代码案例。这个插件用于集成哥伦比亚的Wompi支付网关。

首先,确保你已经在pubspec.yaml文件中添加了wompi_payment_colombia依赖项:

dependencies:
  flutter:
    sdk: flutter
  wompi_payment_colombia: ^最新版本号  # 请替换为最新的版本号

然后运行flutter pub get来获取依赖项。

接下来,你可以按照以下步骤在你的Flutter应用中集成Wompi支付。

1. 初始化插件

在你的Flutter项目的主文件中(通常是main.dart),你需要导入插件并进行初始化。

import 'package:flutter/material.dart';
import 'package:wompi_payment_colombia/wompi_payment_colombia.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final WompiPaymentColombia _wompiPayment = WompiPaymentColombia();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Wompi Payment Example'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            // 打开支付页面
            await _openPaymentPage();
          },
          child: Text('Pay with Wompi'),
        ),
      ),
    );
  }

  Future<void> _openPaymentPage() async {
    try {
      // 配置支付参数
      final Map<String, dynamic> paymentParams = {
        'amount': 10000,  // 支付金额(以最小货币单位表示,例如,10000哥伦比亚比索)
        'currency': 'COP',
        'description': 'Payment description',
        'external_reference': 'unique_payment_id',  // 唯一支付ID
        'name': 'Merchant Name',
        'email': 'customer@example.com',
        'phone': '+57123456789',
        // 你可以根据需要添加更多参数
      };

      // 打开支付页面并等待结果
      final Map<String, dynamic> result = await _wompiPayment.startPayment(paymentParams);

      // 处理支付结果
      if (result['status'] == 'approved') {
        // 支付成功
        print('Payment approved!');
      } else {
        // 支付失败或取消
        print('Payment failed or canceled. Status: ${result['status']}');
      }
    } catch (e) {
      // 处理错误
      print('Error: $e');
    }
  }
}

2. 配置Android和iOS

根据你使用的平台(Android或iOS),你可能需要在AndroidManifest.xmlInfo.plist中进行一些配置,以便插件能够正常工作。具体配置请参考wompi_payment_colombia插件的官方文档。

3. 处理支付回调

在实际应用中,你可能需要处理支付回调,比如通知服务器支付状态。这通常涉及与你的后端服务进行通信,以确保订单状态被正确更新。

注意事项

  • 确保你已经在Wompi平台注册并获得了必要的API密钥和配置。
  • 在实际项目中,处理支付金额时请注意货币单位(例如,哥伦比亚比索的最小单位是1分,而不是1比索)。
  • 遵循最佳实践,确保支付信息的安全传输和存储。

这个示例代码提供了一个基本的框架,你可以根据需要进行扩展和修改。务必参考wompi_payment_colombia插件的官方文档以获取最新的信息和最佳实践。

回到顶部