Skip to content

Commit 4b4388e

Browse files
committed
v6.13.0
1 parent a72e759 commit 4b4388e

File tree

8 files changed

+134
-284
lines changed

8 files changed

+134
-284
lines changed

LabelStoreMax/.env

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ STRIPE_LIVE_MODE=null
3636

3737
# *<! ------ PAYPAL (OPTIONAL) ------!>*
3838

39-
PAYPAL_ACCOUNT_EMAIL=null
40-
# Your PayPal account email e.g. mystore@business.com
41-
PAYPAL_LIVE_MODE=null
39+
PAYPAL_CLIENT_ID=""
40+
PAYPAL_SECRET_KEY=""
41+
42+
PAYPAL_LIVE_MODE=false
4243
# Change to 'true' for live payments
43-
PAYPAL_LOCALE=null
44-
# Use BCP-47 code from this link https://developer.paypal.com/docs/api/reference/locale-codes/
4544

4645
# *<! ------ RAZORPAY (OPTIONAL) ------!>*
4746

LabelStoreMax/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [6.13.0] - 2024-02-12
2+
3+
* Update PayPal integration
4+
* Pubspec.yaml dependency updates
5+
16
## [6.12.7] - 2024-02-11
27

38
* Pubspec.yaml dependency updates
Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,114 @@
1-
//
2-
// LabelCore
3-
// Label StoreMax
1+
// WooGym
42
//
53
// Created by Anthony Gordon.
6-
// 2023, WooSignal Ltd. All rights reserved.
4+
// 2024, WooSignal Ltd. All rights reserved.
75
//
86

97
// Unless required by applicable law or agreed to in writing, software
108
// distributed under the License is distributed on an "AS IS" BASIS,
119
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
//
1310

1411
import 'package:flutter/material.dart';
15-
import 'package:flutter_app/app/models/cart_line_item.dart';
16-
import 'package:flutter_app/bootstrap/data/order_wc.dart';
17-
import 'package:flutter_app/bootstrap/helpers.dart';
18-
import 'package:flutter_app/resources/pages/checkout_confirmation_page.dart';
19-
import 'package:flutter_app/resources/widgets/checkout_paypal.dart';
20-
import 'package:nylo_framework/nylo_framework.dart';
12+
import 'package:flutter_paypal_payment/flutter_paypal_payment.dart';
2113
import 'package:woosignal/models/payload/order_wc.dart';
2214
import 'package:woosignal/models/response/order.dart';
2315
import 'package:woosignal/models/response/tax_rate.dart';
16+
import 'package:woosignal/models/response/woosignal_app.dart';
17+
import '/bootstrap/data/order_wc.dart';
18+
import '/resources/pages/checkout_status_page.dart';
19+
import '/app/models/cart_line_item.dart';
20+
import '/app/models/checkout_session.dart';
21+
import '/resources/pages/checkout_confirmation_page.dart';
22+
import '/bootstrap/app_helper.dart';
23+
import '/bootstrap/helpers.dart';
24+
import 'package:nylo_framework/nylo_framework.dart';
25+
26+
payPalPay(context, {required CheckoutConfirmationPageState state, TaxRate? taxRate}) async {
2427

25-
payPalPay(context,
26-
{required CheckoutConfirmationPageState state, TaxRate? taxRate}) async {
2728
await checkout(taxRate, (total, billingDetails, cart) async {
29+
WooSignalApp? wooSignalApp = AppHelper.instance.appConfig;
30+
2831
List<CartLineItem> cartLineItems = await cart.getCart();
29-
String description = await cart.cartShortDesc();
32+
String cartTotal = await cart.getTotal();
33+
String? currencyCode = wooSignalApp?.currencyMeta?.code;
3034

31-
await Navigator.push(
32-
context,
33-
MaterialPageRoute(
34-
builder: (_) => PayPalCheckout(
35-
description: description,
36-
amount: total,
37-
cartLineItems: cartLineItems))).then((value) async {
38-
if (value is! Map<String, dynamic>) {
39-
showToastNotification(
40-
context,
41-
title: trans("Payment Cancelled"),
42-
description: trans("The payment has been cancelled"),
43-
);
44-
state.reloadState(showLoader: false);
45-
return;
46-
}
35+
String shippingTotal = CheckoutSession.getInstance.shippingType?.getTotal() ?? "0";
4736

48-
state.reloadState(showLoader: true);
49-
if (value.containsKey("status") && value["status"] == "success") {
50-
OrderWC orderWC = await buildOrderWC(taxRate: taxRate, markPaid: true);
51-
Order? order = await (appWooSignal((api) => api.createOrder(orderWC)));
37+
String description = "(${cartLineItems.length}) items from ${getEnv('APP_NAME')}".tr(arguments: {"appName": getEnv('APP_NAME')});
5238

53-
if (order == null) {
39+
Navigator.of(context).push(MaterialPageRoute(
40+
builder: (BuildContext context) => PaypalCheckoutView(
41+
sandboxMode: getEnv('PAYPAL_LIVE_MODE') != true,
42+
clientId: getEnv('PAYPAL_CLIENT_ID'),
43+
secretKey: getEnv('PAYPAL_SECRET_KEY'),
44+
note: "Contact us for any questions on your order.".tr(),
45+
transactions: [
46+
{
47+
"amount": {
48+
"total": total,
49+
"currency": currencyCode?.toUpperCase(),
50+
"details": {
51+
"subtotal": cartTotal,
52+
"shipping": shippingTotal,
53+
"shipping_discount": 0
54+
}
55+
},
56+
"description": description,
57+
"item_list": {
58+
"items": cartLineItems.map((item) => {
59+
"name": item.name,
60+
"quantity": item.quantity,
61+
"price": item.total,
62+
"currency": currencyCode?.toUpperCase()
63+
}).toList(),
64+
65+
"shipping_address": {
66+
"recipient_name": "${billingDetails?.shippingAddress?.nameFull()}",
67+
"line1": billingDetails?.shippingAddress?.addressLine,
68+
"line2": "",
69+
"city": billingDetails?.shippingAddress?.city,
70+
"country_code": billingDetails?.shippingAddress?.customerCountry?.countryCode,
71+
"postal_code": billingDetails?.shippingAddress?.postalCode,
72+
"phone": billingDetails?.shippingAddress?.phoneNumber,
73+
"state": billingDetails?.shippingAddress?.customerCountry?.state?.name
74+
},
75+
}
76+
}
77+
],
78+
onSuccess: (Map params) async {
79+
OrderWC orderWC = await buildOrderWC(taxRate: taxRate);
80+
Order? order = await (appWooSignal((api) => api.createOrder(orderWC)));
81+
82+
if (order == null) {
83+
showToastNotification(
84+
context,
85+
title: trans("Error"),
86+
description: trans("Something went wrong, please contact our store"),
87+
);
88+
state.reloadState(showLoader: false);
89+
return;
90+
}
91+
92+
routeTo(CheckoutStatusPage.path, data: order);
93+
},
94+
onError: (error) {
95+
NyLogger.error(error.toString());
5496
showToastNotification(
5597
context,
5698
title: trans("Error"),
5799
description:
58-
trans("Something went wrong, please contact our store"),
100+
trans("Something went wrong, please contact our store"),
101+
);
102+
updateState(CheckoutConfirmationPage.path, data: {"reloadState": false});
103+
},
104+
onCancel: () {
105+
showToastNotification(
106+
context,
107+
title: trans("Payment Cancelled"),
108+
description: trans("The payment has been cancelled"),
59109
);
60-
return;
61-
}
62-
Navigator.pushNamed(context, "/checkout-status", arguments: order);
63-
return;
64-
} else {
65-
showToastNotification(
66-
context,
67-
title: trans("Payment Cancelled"),
68-
description: trans("The payment has been cancelled"),
69-
);
70-
}
71-
});
72-
state.reloadState(showLoader: false);
110+
updateState(CheckoutConfirmationPage.path, data: {"reloadState": false});
111+
},
112+
),),);
73113
});
74114
}

LabelStoreMax/lib/resources/pages/checkout_confirmation_page.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ import 'package:woosignal/models/response/tax_rate.dart';
3232
import 'package:woosignal/models/response/woosignal_app.dart';
3333

3434
class CheckoutConfirmationPage extends StatefulWidget {
35+
static String path = '/checkout';
3536
CheckoutConfirmationPage({Key? key}) : super(key: key);
3637

3738
@override
38-
CheckoutConfirmationPageState createState() =>
39+
createState() =>
3940
CheckoutConfirmationPageState();
4041
}
4142

@@ -49,7 +50,6 @@ class CheckoutConfirmationPageState extends NyState<CheckoutConfirmationPage> {
4950

5051
@override
5152
init() async {
52-
super.init();
5353
CheckoutSession.getInstance.coupon = null;
5454
List<PaymentType?> paymentTypes = await getPaymentTypes();
5555

@@ -62,6 +62,17 @@ class CheckoutConfirmationPageState extends NyState<CheckoutConfirmationPage> {
6262
_getTaxes();
6363
}
6464

65+
@override
66+
stateUpdated(dynamic data) async {
67+
if (data == null) return;
68+
if (data['reloadState'] != null) {
69+
reloadState(showLoader: data['reloadState']);
70+
}
71+
if (data['refresh'] != null) {
72+
setState(() {});
73+
}
74+
}
75+
6576
reloadState({required bool showLoader}) {
6677
setState(() {
6778
_showFullLoader = showLoader;

0 commit comments

Comments
 (0)