hyperpay_plugin 1.0.7 copy "hyperpay_plugin: ^1.0.7" to clipboard
hyperpay_plugin: ^1.0.7 copied to clipboard

The HyperPay platform offers a complete, easy-to-use guide to enable seamless integration of our end-to-end payment gateway for mobile.

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:hyperpay_plugin/flutter_hyperpay.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'dart:developer' as dev;

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {

  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  late FlutterHyperPay flutterHyperPay ;
  @override
  void initState() {
    flutterHyperPay = FlutterHyperPay(
      shopperResultUrl: InAppPaymentSetting.shopperResultUrl,
      paymentMode:  PaymentMode.test,
      lang: InAppPaymentSetting.getLang(),
    );
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:const Text("Payment"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("pay with ready ui".toUpperCase() , style: const TextStyle(fontSize: 20 , color: Colors.red),),
            InkWell( onTap: (){getCheckOut(brandName: "VISA");}, child: const Text("VISA" , style: TextStyle(fontSize: 20),)),
            InkWell( onTap: (){getCheckOut(brandName: "MASTER");}, child: const Text("MASTER" , style: TextStyle(fontSize: 20),)),
            InkWell( onTap: (){getCheckOut(brandName: "MADA");}, child: const Text("MADA" , style: TextStyle(fontSize: 20),)),
            InkWell( onTap: (){getCheckOut(brandName: "STC_PAY");}, child: const Text("STC_PAY" , style: TextStyle(fontSize: 20),)),
            Platform.isIOS
                ? InkWell( onTap: (){getCheckOut(brandName: "APPLEPAY");}, child: const Text("APPLEPAY" , style: TextStyle(fontSize: 20),))
                : Container(),

            const Divider(),
            Text("pay with custom ui".toUpperCase() , style: const TextStyle(fontSize: 20 , color: Colors.red),),
            InkWell( onTap: (){getCheckOut(brandName: "VISA" ,cardNumber: "4111111111111111" ,  payWithReadyUi: false);}, child: const Text("VISA" , style: TextStyle(fontSize: 20),)),
            InkWell( onTap: (){getCheckOut(brandName: "MASTER" ,cardNumber: "5541805721646120", payWithReadyUi: false);}, child: const Text("MASTER" , style: TextStyle(fontSize: 20),)),
            InkWell( onTap: (){getCheckOut(brandName: "MADA" ,cardNumber: "5541805721646120", payWithReadyUi: false);}, child: const Text("MADA" , style: TextStyle(fontSize: 20),)),
            const Divider(),
            Text("pay with custom ui stc".toUpperCase() , style: const TextStyle(fontSize: 20 , color: Colors.red),),
            InkWell( onTap: (){
              payRequestNowCustomUiSTCPAY(checkoutId: "64AC8464BF6209E8EDC21BE0B614B673.uat01-vm-tx01", phoneNumber: "0588987147");

            }, child: const Text("STC_PAY" , style: TextStyle(fontSize: 20),)),

          ],
        ),
      ),
    );
  }

  /// URL TO GET CHECKOUT ID FOR TEST
  /// http://dev.hyperpay.com/hyperpay-demo/getcheckoutid.php
  /// Brands Names [ VISA , MASTER , MADA , STC_PAY , APPLEPAY]

  getCheckOut({required String brandName , bool payWithReadyUi = true , String? cardNumber }) async {
    final url = Uri.parse('https://dev.hyperpay.com/hyperpay-demo/getcheckoutid.php');
    final response = await http.get(url);
    if (response.statusCode == 200) {

        if(payWithReadyUi) {
          payRequestNowReadyUI(checkoutId: json.decode(response.body)['id'], brandName: brandName);
        }else{
          payRequestNowCustomUi(checkoutId: json.decode(response.body)['id'], brandName: brandName , cardNumber: cardNumber!);
        }

    }else{
      dev.log(response.body.toString(), name: "STATUS CODE ERROR");
    }
  }

  payRequestNowReadyUI(
      {required String brandName, required String checkoutId}) async {
    PaymentResultData paymentResultData;
    if (brandName.toLowerCase() == InAppPaymentSetting.applePay.toLowerCase()) {
      paymentResultData = await flutterHyperPay.payWithApplePay(
        applePay: ApplePay(
          /// ApplePayBundel refer to Merchant ID
            applePayBundel: InAppPaymentSetting.merchantId,
            checkoutId: checkoutId,
            countryCode: InAppPaymentSetting.countryCode,
            currencyCode: InAppPaymentSetting.currencyCode,
            themColorHexIOS: "#000000", // FOR IOS ONLY
            companyName: "Test Co"),
      );
    } else {
      paymentResultData = await flutterHyperPay.readyUICards(
        readyUI: ReadyUI(
            brandName: brandName,
            checkoutId: checkoutId,
            setStorePaymentDetailsMode: false,
            themColorHexIOS: "#000000" // FOR IOS ONLY
            ),
      );
    }

    if (paymentResultData.paymentResult == PaymentResult.success ||
        paymentResultData.paymentResult == PaymentResult.sync) {
      // do something
    }
  }

  payRequestNowCustomUi(
      {required String brandName, required String checkoutId , required String cardNumber}) async {
    PaymentResultData paymentResultData;

    paymentResultData = await flutterHyperPay.customUICards(
      customUI: CustomUI(
        brandName: brandName,
        checkoutId: checkoutId,
        cardNumber: cardNumber,
        holderName: "test name",
        month: 12,
        year: 2023,
        cvv: 123,
        enabledTokenization: false, // default
      ),
    );

    if (paymentResultData.paymentResult == PaymentResult.success ||
        paymentResultData.paymentResult == PaymentResult.sync) {
      // do something
    }
  }

  payRequestNowCustomUiSTCPAY(
      {required String phoneNumber, required String checkoutId}) async {
    PaymentResultData paymentResultData;

    paymentResultData = await flutterHyperPay.customUISTC(
      customUISTC: CustomUISTC(
          checkoutId: checkoutId,
          phoneNumber: phoneNumber
      ),
    );

    if (paymentResultData.paymentResult == PaymentResult.success ||
        paymentResultData.paymentResult == PaymentResult.sync) {
      // do something
    }
  }
}

class InAppPaymentSetting {
  static const String applePay="APPLEPAY";
  static const String shopperResultUrl= "com.testpayment.payment";
  static const String merchantId= "MerchantId";
  static const String countryCode="SA";
  static const String currencyCode="SAR";
  static getLang() {
    if (Platform.isIOS) {
      return  "en"; // ar
    } else {
      return "en_US"; // ar_AR
    }
  }
}
36
likes
0
pub points
87%
popularity

Publisher

unverified uploader

The HyperPay platform offers a complete, easy-to-use guide to enable seamless integration of our end-to-end payment gateway for mobile.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on hyperpay_plugin