Skip to content

Latest commit

 

History

History

payu_mobile_payments

Features

Flutter plugin which allows make payments via Apple Pay / Google Pay

Apple Pay

Getting started

Apple Pay™ is a digital wallet which lets you make card payments in a simple and fast manner, without having to enter your card details every time. The card data is securely stored by Apple. This payment method is available for selected browsers and Apple devices (phones and computers). A full list of supported countries and devices can be found on the Apple website.

Configuration

Setup

  1. Enable Apple Pay
  2. Create a merchant identifier
  3. Create a payment processing certificate
  4. Send created payment processing certificate to tech@payu.pl

When creating an Apple Pay Payment Processing Certificate, you must specify the Key Pair information. Select ECC and 256 bit key pair.

Enable

The Apple Pay payment method is also available in a sandbox environment. In the integration process, we suggest creating an independent Merchant ID (with a name ending “.test”, for example) together with a set of certificates.

Because Apple Pay is not the default payment method, please contact the tech@payu.pl after registering in the sandbox environment, but before beginning integration using the Apple Pay payment method. In response you receive also CSR file for sandbox environment.

Testing

Before beginning to perform tests in the sandbox, please also read the Apple Pay Sandbox Testing instructions.

We recommend using the card numbers since these are configured in the PayU sandbox to enable payments to be completed successfully:

  • 5204 2477 5000 1471
  • 4761 1200 1000 0492

Integration

import 'package:example/core/ui/snackbar.dart';
import 'package:flutter/material.dart';
import 'package:payu/payu.dart';

void main() {
  Payu.debug = true;
  Payu.locale = const Locale('en');
  Payu.environment = Environment.sandbox;
  Payu.pos = const POS(id: '300746');

  runApp(
    const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    ),
  );
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  late final PayuMobilePayments _service;

  @override
  void initState() {
    _service = PayuMobilePayments();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Payu.theme,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('HomePage'),
        ),
        body: Column(
          children: [
            TextButton(
              onPressed: () => _didTapPay(_buildApplePayPaymentConfiguration()),
              child: const Text('ApplePay'),
            ),
          ],
        ),
      ),
    );
  }

  void _didTapPay(PaymentConfiguration paymentConfiguration) async {
    if (await _service.canMakePayment(paymentConfiguration)) {
      final authorizationCode = await _service.makePayment(paymentConfiguration);
      snackbar('authorizationCode: $authorizationCode');
    }
  }

  PaymentConfiguration _buildApplePayPaymentConfiguration() {
    return PaymentConfiguration.applePay(
      request: ApplePayPaymentRequestBuilder()
          .withCountryCode('PL')
          .withCurrencyCode('PLN')
          .withMerchantIdentifier('merchantIdentifier')
          .withShippingContact(
            const ApplePayContact(
              emailAddress: 'email@address.com',
            ),
          )
          .withPaymentSummaryItems(
        const [
          ApplePaySummaryItem(label: 'Futomaki', amount: 1599),
          ApplePaySummaryItem(label: 'Napkin', amount: 49),
          ApplePaySummaryItem(label: 'Order', amount: 1599 + 49),
        ],
      ).build(),
    );
  }
}

Google Pay

Getting started

To enable Google Pay you should have configurated POS with Google Pay enabled on PayU backend.

Requirements

  1. minSdkVersion 19
  2. Google account on the device you are testing.

Integration

import 'package:example/core/ui/snackbar.dart';
import 'package:flutter/material.dart';
import 'package:payu/payu.dart';

void main() {
  Payu.debug = true;
  Payu.locale = const Locale('en');
  Payu.environment = Environment.sandbox;
  Payu.pos = const POS(id: '300746');

  runApp(
    const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    ),
  );
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  late final PayuMobilePayments _service;

  @override
  void initState() {
    _service = PayuMobilePayments();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Payu.theme,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('HomePage'),
        ),
        body: Column(
          children: [
            TextButton(
              onPressed: () => _didTapPay(_buildGooglePayPaymentConfiguration()),
              child: const Text('GooglePay'),
            ),
          ],
        ),
      ),
    );
  }

  void _didTapPay(PaymentConfiguration paymentConfiguration) async {
    if (await _service.canMakePayment(paymentConfiguration)) {
      final authorizationCode = await _service.makePayment(paymentConfiguration);
      snackbar('authorizationCode: $authorizationCode');
    }
  }

  PaymentConfiguration _buildGooglePayPaymentConfiguration() {
    return PaymentConfiguration.googlePay(
      environment: PaymentEnvironment.test,
      request: GooglePayPaymentDataRequestBuilder()
          .withMerchantId('merchantId')
          .withMerchantName('merchantName')
          .withCountryCode('PL')
          .withCurrencyCode('PLN')
          .withTotalPrice('1.23')
          .build(),
    );
  }
}

Additional information

TODO: Tell users more about the package: where to find more information, how to contribute to the package, how to file issues, what response they can expect from the package authors, and more.