following section gives payment button for apple pay
<code>if (_selectedMethodIndex == 4)
BottomAppBar(
child: SizedBox(
width: double.infinity,
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0),
child: PlatformPayButton(
onPressed: () {
print('apple pay loading');
_handleApplePayPress(context);
},
// onPressed: () =>
// _handleApplePayPress(context),
),
),
),
),
),
</code>
<code>if (_selectedMethodIndex == 4)
BottomAppBar(
child: SizedBox(
width: double.infinity,
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0),
child: PlatformPayButton(
onPressed: () {
print('apple pay loading');
_handleApplePayPress(context);
},
// onPressed: () =>
// _handleApplePayPress(context),
),
),
),
),
),
</code>
if (_selectedMethodIndex == 4)
BottomAppBar(
child: SizedBox(
width: double.infinity,
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0),
child: PlatformPayButton(
onPressed: () {
print('apple pay loading');
_handleApplePayPress(context);
},
// onPressed: () =>
// _handleApplePayPress(context),
),
),
),
),
),
then further for handling the press event following section is written down:
<code>void _handleApplePayPress(BuildContext context) async{
print('pay pressed');
try {
if (await Stripe.instance.isPlatformPaySupported()) {
print('apple pay is supported');
bool paymentSuccessful = await _payWithApplePay() ?? false;
if (paymentSuccessful) {
// If payment is successful then execute this code
print('payment successful');
} else {
// if payment failed
print('payment failed');
}
} else {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Apple pay is not supported in this device'),
));
}
} catch (exception) {
print(exception.toString());
}
</code>
<code>void _handleApplePayPress(BuildContext context) async{
print('pay pressed');
try {
if (await Stripe.instance.isPlatformPaySupported()) {
print('apple pay is supported');
bool paymentSuccessful = await _payWithApplePay() ?? false;
if (paymentSuccessful) {
// If payment is successful then execute this code
print('payment successful');
} else {
// if payment failed
print('payment failed');
}
} else {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Apple pay is not supported in this device'),
));
}
} catch (exception) {
print(exception.toString());
}
</code>
void _handleApplePayPress(BuildContext context) async{
print('pay pressed');
try {
if (await Stripe.instance.isPlatformPaySupported()) {
print('apple pay is supported');
bool paymentSuccessful = await _payWithApplePay() ?? false;
if (paymentSuccessful) {
// If payment is successful then execute this code
print('payment successful');
} else {
// if payment failed
print('payment failed');
}
} else {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Apple pay is not supported in this device'),
));
}
} catch (exception) {
print(exception.toString());
}
}
<code>Future<bool?> _payWithApplePay() async{
print("controller methods");
}
</code>
<code>Future<bool?> _payWithApplePay() async{
print("controller methods");
}
</code>
Future<bool?> _payWithApplePay() async{
print("controller methods");
}
i did this
i got the Apple pay button
now i need to do further processing which i don’t know how to do..