패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.2.0

paynow

결제를 시작하는 데 도움이 되는 Paynow 클라이언트 보조 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
69
좋아요
26
Pub 점수
140

패키지 설치

flutter pub add paynow

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

paynow 패키지는 앱에 Paynow 결제 서비스를 통합하는 것을 간편하게 만드는 Flutter/Dart 클라이언트 도우미입니다. 결제 시작, 거래 상태 관리, 여러 플랫폼에서 응답 처리를 위한 간소화된 메서드를 제공합니다. 개발자들이 Paynow 결제 게이트웨이 기능을 신뢰할 수 있는 방식으로 내장하고자 할 때 사용되며, Android, iOS, Web, macOS, Windows, Linux를 지원합니다. 복잡한 API 상호작용을 추상화하여 최소한의 부가 코드로 빠르게 구현할 수 있습니다. Paynow가 널리 사용되는 지역에서 안전하고 크로스플랫폼 결제 처리가 필요한 앱에 적합합니다.

사용 사례

  • 모바일 앱에 Paynow 결제 통합
  • 웹 기반 결제 흐름 활성화
  • 다중 플랫폼 결제 솔루션 지원
  • 실시간 거래 상태 업데이트 처리
  • Paynow로 전자상거래 애플리케이션 만들기
  • 지급 시작 워크플로우 자동화

주요 기능

  • 크로스 플랫폼 호환성
  • 간단한 결제 시작 API
  • 거래 상태 모니터링
  • 안전한 결제 처리
  • 내장된 오류 처리
  • 다중 운영 체제 지원

적합한 대상

  • 결제 기능을 갖춘 앱을 개발하는 플러터 개발자
  • 아프리카에서 Paynow를 통합하는 스타트업
  • 현지 결제 옵션이 필요한 전자상거래 플랫폼
  • 짐바브웨 또는 아프리카 시장을 겨냥한 앱
  • 빠른 Paynow 통합을 원하는 개발자

고려 사항

  • 유효한 Paynow API 자격 증명이 필요합니다
  • Paynow 백엔드의 가용성에 따라 달라짐
  • 완전한 사용자 경험을 위해 추가적인 UI 컴포넌트가 필요할 수 있습니다
  • Paynow가 아닌 결제 게이트웨이에는 적합하지 않습니다
  • 기본 사용법 외에 문서가 제한적
  • 플랫폼별 구성이 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.


id: flutter_quickstart title: Flutter Guide sidebar_label: Dart

Sign in to Paynow and get integration details

Before you can start making requests to Paynow's API, you need to get an integration ID and integration Key from Paynow. Details about how you can retrieve the ID and key are explained in detail on this page

Prerequisites

In order to make use of this project, the following prerequisites must be met for it to work.

  1. Latest Flutter SDK Version

Installation

To use the Flutter Paynow SDK, you need to add the latest release as a dependency to your project by updating your pubspec.yaml.
The latest release will be on the pub.dev.

pubspec.yaml
  paynow: ^latest_version

Getting started

Create an instance of Paynow associated with your integration ID and integration key as supplied by Paynow.

Import the paynow package

    import 'package:paynow/paynow.dart';

Initialise Paynow

    Paynow paynow = Paynow(integrationKey: "INTEGRATION_KEY", integrationId: "INTEGRATION_ID", returnUrl: "http://yourReturnUrl.com", resultUrl: "http://yourResultUrl.com");

Create Payment Instance

Create a new payment using any of the createPayment(...) methods, ensuring you pass your own unique reference for that payment (e.g invoice id). If you also pass in the email address, Paynow will attempt to auto login the customer at the Paynow website using this email address if it is associated with a registered account.

    Payment payment = paynow.createPayment("Invoice 32", "client@email.com");

Create Item to Add to cart

    final cartItem = PaynowCartItem(title : 'Banana', amount: 20.0)

    // add to cart
    payment.addToCart(cartItem);

    // add to cart with specific quantity
    payment.addToCart(cartItem, quantity: 5);

Remove item from cart

    // Remove 1 unit of the item in the cart
    payment.removeFromCart(cartItem);

    // Remove specific quantity of items in cart
    payment.remoteFromCart(cartItem, quantity: 5);

    // Remove item from cart completely
    payment.deleteCartItem(cartItem);

Initiating a web based transaction

A web based transaction is made over the web, via the Paynow website.

You can optionally set the result and return URLs.

  • Result URL is the URL on the merchant website where Paynow will post transaction results to.
  • Return URL is the URL where the customer will be redirected to after the transaction has been processed. If you do not specify a return URL, you will have to rely solely on polling status updates to determine if the transaction has been paid.
    paynow.setResultUrl("http://example.com/gateways/paynow/update");
    paynow.setReturnUrl("http://example.com/return?gateway=paynow&merchantReference=1234");
    InitResponse response  = await paynow.send(payment);

The InitResponse response from Paynow will contain various information including:

  • url to redirect your customer to complete payment.
  • poll URL to check if the transaction has been paid

Initiating a mobile based transaction

A mobile transaction is a transaction made using mobile money e.g. using Ecocash

Note: Mobile based transactions currently only work for Ecocash with Econet numbers and OneMoney with Netone numbers

Create a new payment using the createPayment(...) method that requires a unique merchant reference and the email address of the user making the payment.

    InitResponse response = await paynow.sendMobile(payment, "0784442662", MobilePaymentMethod.ecocash);

Check Response results

The InitResponse response from Paynow will contain various information including:

  • url to redirect your customer to complete payment.
  • poll URL to check if the transaction has been paid
    // Display results
    print(response());

    // Print Instructions
    print(response.instructions);

    // For Web Checkout, you get your [redirect_url] to redirect your client to
    String redirectuUrl = response.redirectUrl

Poll the transaction to check for the payment status

It is possible to check the status of a transaction i.e. if the payment has been paid. To do this, make sure after initiating the transaction, you take note of the poll URL in the response. With this URL, call the pollTransaction(...) method of the Paynow object you created as follows. Note that checking transaction status is the same for web and mobile based transasctions.

If the request was successful, you should consider saving the poll URL sent from Paynow in your database so that you can use it later to check if the transaction has been paid.

    InitResponse response = await paynow.send(payment);
    StatusResponse statusResponse = await paynow.checkTransactionStatus(response.pollUrl);

    if (statusResponse.status == "Paid"){
        print("Client Paid");
    }
    else{
        print("Transaction was unsuccessful");
    }

Serverless Express Checkout in v1.1.x (stream transaction for payment status)

You are now able to stream poll url transaction status as opposed to using delay for a serverless checkout. This is useful when you dont have a server to check paynow result url as set by resultUrl and returnUrl attributes

  • Full test example can be found here under test folder
  • paynow.streamTransactionStatus(..) takes a required pollUrl string and optional streamInterval in seconds which is the interval to poll the url, default to 20 sec
  • You can stream status and show current transaction status on UI to user with a StreamBuilder(..)
  • Check example folder for a full example
 // grab poll url from `StatusResponse` object or database
 var pollUrl = statusResponse.pollUrl;

 // in Widget build(..) method
 // you can do something like
 StreamBuilder(
     stream: paynow.streamTransactionStatus(pollUrl),
     builder: (context, AsyncSnapshot<StatusResponse> snapshot) {
         if(snapshot.hasData) {
             var response = snapshot.data;

             // check status or bool flag here
             return _trxnStatus(response.status);
         }

         else {
             return CircularProgressIndicator();
         }
     }
 )

 // return a widget based on status from stream
 Widget _trxnStatus(String status) {
    switch(status) {
        case 'Paid':
            return Text('Transaction Successfully Paid');
            break;

        case 'Sent':
            return Container(
                height: 130,
                Column(
                    children: [
                        Text('Payment request sent'),
                        SizedBox(height: 20),
                        CircularProgressIndicator(),
                        Text('waiting for response...'),
                    ],
                ),
            );
            break;

        case 'Cancelled':
            return Text('You have cancelled payment request');
            break;

        default:
            return SizedBox.shrink();
     }
 }

Full usage example

The following is a usage example for mobile based transactions. For a full usage example please check the example folder.

   import 'package:paynow/paynow.dart';

   main()async{
      Paynow paynow = Paynow(integrationId: '', integrationKey: '', resultUrl: '', returnUrl :'');
      Payment payment = paynow.createPayment('Invoice 32', 'user@email.com');

      // add something to cart
      payment.add('Banana', 10.0);

      // start web checkout
      InitResponse response = await payment.sendMobile(payment, '0784442662', MobilePaymentMethod.ecocash);

      //delay
      await Future.delayed(Duration(seconds: 3));

      // check transaction status
      StatusResponse status = await paynow.checkTransactionStatus(response.pollUrl);

      if (status.status == "Paid"){
        print('Yes!!!!!');
      }else{
        print('You didn\'t pay');
      }
   }

Note

The next release of this package will have null-safety enabled. This will be a breaking change as version 2.x.x will be released soon.

Happy Coding :)

카테고리

의존성

의존성 목록 6 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.