First Payment
Create your first payment with YagoutPay Flutter SDK.
Learn how to create your first payment using the YagoutPay Flutter SDK with a simple hosted payment integration.
Prerequisites
- Flutter SDK installed and configured
- YagoutPay Flutter SDK added to your project
- Valid API credentials from your YagoutPay dashboard
Create Your First Payment
Here's a simple example to create a payment:
import 'package:yagoutpay_flutter/yagoutpay_flutter.dart';
class PaymentService {
static Future<PaymentResult> createPayment({
required String amount,
required String currency,
required String description,
}) async {
try {
final payment = await YagoutPay.createPayment(
amount: amount,
currency: currency,
description: description,
successUrl: 'https://yourapp.com/success',
cancelUrl: 'https://yourapp.com/cancel',
);
return PaymentResult.success(payment);
} catch (e) {
return PaymentResult.error(e.toString());
}
}
}
Handle Payment Result
Handle the payment result in your UI:
ElevatedButton(
onPressed: () async {
final result = await PaymentService.createPayment(
amount: '1000', // Amount in cents
currency: 'USD',
description: 'Test Payment',
);
if (result.isSuccess) {
// Payment created successfully
print('Payment ID: ${result.payment?.id}');
} else {
// Handle error
print('Error: ${result.error}');
}
},
child: Text('Create Payment'),
)
NEXT STEPS
After creating your first payment, explore Hosted Payments for more advanced integration options.