Payment Links
Generate shareable payment links for your Flutter app.
Payment links allow you to generate shareable payment URLs that customers can use to complete payments via SMS, email, or WhatsApp.
Features
- ✅ Shareable payment URLs
- ✅ SMS/Email integration
- ✅ WhatsApp sharing
- ✅ Expiry date support
Implementation
Create payment links with the following service:
static Future<Map<String, dynamic>> createPaymentLink({
required String reqUserId,
required String amount,
required String customerEmail,
required String mobileNo,
required String expiryDate,
required String orderId,
required String firstName,
required String lastName,
required String product,
required String dialCode,
required String failureUrl,
required String successUrl,
String country = 'ETH',
String currency = 'ETB',
List<String> mediaType = const ['API'],
}) async {
final meId = YagoutPayConfig.apiMerchantId;
final key = YagoutPayConfig.apiKey;
// Build payload
final payload = {
'req_user_id': reqUserId,
'me_id': meId,
'amount': amount,
'customer_email': customerEmail,
'mobile_no': mobileNo,
'expiry_date': expiryDate,
'media_type': mediaType,
'order_id': orderId,
'first_name': firstName,
'last_name': lastName,
'product': product,
'dial_code': dialCode,
'failure_url': failureUrl,
'success_url': successUrl,
'country': country,
'currency': currency,
};
// Encrypt payload
final plainStr = jsonEncode(payload);
final encrypted = AesUtil.encryptToBase64(plainStr, key);
// Make API request
final response = await http.post(
Uri.parse(YagoutPayConfig.paymentLinkUrl),
headers: {
'Content-Type': 'application/json',
'me_id': meId,
},
body: jsonEncode({'request': encrypted}),
);
// Process response
final responseData = json.decode(response.body);
return {
'status': responseData['status'] ?? 'ERROR',
'message': responseData['statusMessage'] ?? 'Unknown error',
'order_id': orderId,
'response': responseData,
};
}
Usage in Flutter
// Create payment link
Future<void> _createPaymentLink() async {
final result = await YagoutPayService.createPaymentLink(
reqUserId: 'user123',
amount: '100.00',
customerEmail: 'customer@example.com',
mobileNo: '+251912345678',
expiryDate: '2025-12-31',
orderId: 'ORDER-123',
firstName: 'John',
lastName: 'Doe',
product: 'Premium Subscription',
dialCode: '+251',
failureUrl: 'https://yourapp.com/failure',
successUrl: 'https://yourapp.com/success',
);
if (result['status'] == 'SUCCESS') {
// Share payment link
_sharePaymentLink(result['payment_link']);
}
}
NEXT STEPS
Learn about Static Links for QR code generation and recurring payments.