Giter Club home page Giter Club logo

youcan-pay-flutter-sdk's Introduction

YouCanPay Flutter SDK makes it quick and easy to build an excellent payment experience in your Android & iOS apps with YouCan Pay API. We provide powerful and customizable UI screens to make your payment more easier

Basic Usage

Server-side

This integration requires endpoints on your server in order to communicate with YouCanPay API. Use our official libraries for access to the YouCanPay API from your server: the following steps in our Documentation will guide you through.

Install the YouCan Pay SDK :

Add youcanpay to your pubspec.yaml file:

dependencies:
  youcanpay_sdk: <version>

Or run following command line

flutter pub add youcanpay_sdk

Import it

Now in your Dart code, you can use:

import 'package:youcanpay_sdk/youcanpay_sdk.dart';

Set up Payment :

Initials YCPay

The first step is to initialize YouCanPay SDK by creating an instance using the following parameters : pub_key and context

late YCPay ycPay;

and instantiate it in your initState method

@override
  void initState() {
    super.initState();
     ycPay = YCPay(
        publicKey: publicKey,
        context: context
    );
  }
pub_key

The seller's YouCanPay account public key. This lets us know who is receiving the payment.

Load supported payment methods

After we initials ycPay we can load the supprted payment methods using:

ycPay.getAccountConfig().then((accountConfig){
           if (!accountConfig.success) {
            	// load config failed.
               return;
           }

           if (accountConfig.acceptsCashPlus) {
               // CashPlus is available
           }
   
           if (accountConfig.acceptsCreditCards) {
               // Credit cards are available
           }
       });

Start Payment Using Credit Card:

When you get accountConfig.acceptsCreditCard == true it means that the Credit Card payment method is allowed.

Initials Card Information
try{
   cardInformation = CardInformation(
       cardHolderName: 'Holder Name',
       cardNumber: '1234123412341234',
       expireDateYear: '35', // YY
       expireDateMonth: '12', // MM
       cvv: '123');
} catch(e) {
   print(e); // Invalid CardInformation Exception error
}
Proceed payment using Credit Card:

You can use ycPay.payWithCard to proceed your payment use as parameters the token_id it can be generated from your server side and received through an endpoint to the mobile application, to generate a token please refer to the Tokenization section.

ycPay.payWithCard(
        token: "token_id"
        cardInformation: cardInformation,       
        onSuccessfulPayment: (transactionId) {
            // ... pay success
         },
        onFailedPayment: (errorMessage) {
            // ... pay Failure with reason
        },
);

Once the onSuccessfulPayment callback invoked it means that the transaction is processeded successfully, a transactionId will be received as a parameter that you can submit with your order details. Similarly, onFailedPayment is called when an error is occurred during the payment, and you get the errorMessage as a parameter to show to customer.

Start Payment Using CashPlus:

If you you get accountConfig.acceptsCashPlus == true that's mean that you have CashPlus as a payment method

Proceed payment using CashPlus:

You can use ycPay.payWithCashPlus to proceed your payment use as parameter the token_id it can be generated from your server side and received through an endpoint to the mobile application, to generate a token please refer to the Tokenization section.

ycPay.payWithCashPlus(
         token: "token_id", 
         onSuccessfulPayment: (transactionId, cashPlusToken) {
             // ... pay success
          }, 
         onFailedPayment: (errorMessage) {
             // ... pay Failure with reason
          }
 );

Once the onSuccessfulPayment callback invoked it means that the transaction is processeded successfully, a transactionId and cashPlusToken will be received as a parameter that you can submit with your order details. Similarly, onFailedPayment is called when an error is occurred during the payment, and you get the errorMessageas a parameter to show to customer.

Sandbox

YouCan Pay Sandbox offers an easy way for developers to test YouCan Pay in their test environment.

// setting the sandbox mode
 ycPay = YCPay(
        publicKey: publicKey,
        context: context,
        sandbox: true // <--
    );

youcan-pay-flutter-sdk's People

Contributors

abdelmjid-asouab avatar hamzamihfad avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.