Flutter plugin which allows make payments via Apple Pay / Google Pay
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.
- Enable Apple Pay
- Create a merchant identifier
- Create a payment processing certificate
- 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.
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.
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
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(),
);
}
}
To enable Google Pay you should have configurated POS with Google Pay enabled on PayU backend.
minSdkVersion
19- Google account on the device you are testing.
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(),
);
}
}
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.