Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beasy-mobile
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
G
beasy-mobile
Commits
3cd6096a
Commit
3cd6096a
authored
May 28, 2024
by
G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- put the logic of orange payment inside its own function
- show modal depending on the type of error we got while processing.
parent
2e7293ca
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
23 deletions
+40
-23
PaymentAmountInputScreen.tsx
src/screens/PaymentAmountInputScreen.tsx
+40
-23
No files found.
src/screens/PaymentAmountInputScreen.tsx
View file @
3cd6096a
import
{
useModalsManagerContext
}
from
"@/contexts/ModalsManagerContext"
;
import
type
{
PaymentStackScreenComponentProps
}
from
"@/navigations/Types"
;
import
type
{
PaymentStackScreenComponentProps
}
from
"@/navigations/Types"
;
import
BeasyLogoIcon
from
"@components/BeasyLogoIcon"
;
import
BeasyLogoIcon
from
"@components/BeasyLogoIcon"
;
import
Button
from
"@components/Button"
;
import
Button
from
"@components/Button"
;
...
@@ -7,6 +8,8 @@ import PaymentOption from "@components/PaymentOption";
...
@@ -7,6 +8,8 @@ import PaymentOption from "@components/PaymentOption";
import
BackgroundDefault
from
"@components/backgrounds/BackgroundDefault"
;
import
BackgroundDefault
from
"@components/backgrounds/BackgroundDefault"
;
import
Box
from
"@components/bases/Box"
;
import
Box
from
"@components/bases/Box"
;
import
Text
from
"@components/bases/Text"
;
import
Text
from
"@components/bases/Text"
;
import
ErrorModal
from
"@components/modals/ErrorModal"
;
import
LoadingModal
from
"@components/modals/LoadingModal"
;
import
useOrangeMoney
from
"@hooks/useOrangeMoney"
;
import
useOrangeMoney
from
"@hooks/useOrangeMoney"
;
import
{
LOG
}
from
"@logger"
;
import
{
LOG
}
from
"@logger"
;
import
{
useCallback
,
useState
}
from
"react"
;
import
{
useCallback
,
useState
}
from
"react"
;
...
@@ -21,6 +24,7 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
...
@@ -21,6 +24,7 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
log
.
debug
(
"PaymentAmountInputScreen"
);
log
.
debug
(
"PaymentAmountInputScreen"
);
const
{
paymentType
}
=
route
.
params
;
const
{
paymentType
}
=
route
.
params
;
const
[
amountToPay
,
setAmountToPay
]
=
useState
(
0
);
const
[
amountToPay
,
setAmountToPay
]
=
useState
(
0
);
const
{
showModal
,
closeModal
}
=
useModalsManagerContext
();
const
{
const
{
orangeTransactionInitializerMutation
,
orangeTransactionInitializerMutation
,
...
@@ -48,35 +52,55 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
...
@@ -48,35 +52,55 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
return
setAmountToPay
(
0
);
return
setAmountToPay
(
0
);
};
};
const
handlePaymentButton
=
useCallback
(
async
()
=>
{
const
orangePaymentSequence
=
useCallback
(
async
()
=>
{
switch
(
paymentType
)
{
case
"OM"
:
{
Keyboard
.
dismiss
();
log
.
info
(
"OM so we stays on screen !!"
);
log
.
info
(
"Calling api with amount :: "
,
amountToPay
);
log
.
info
(
"Calling api with amount :: "
,
amountToPay
);
try
{
try
{
showModal
(<
LoadingModal
message=
"Initialization de la transaction."
/>);
const
{
payment_url
,
order_id
}
=
const
{
payment_url
,
order_id
}
=
await
orangeTransactionInitializerMutation
.
mutateAsync
(
amountToPay
);
await
orangeTransactionInitializerMutation
.
mutateAsync
(
amountToPay
);
// closeModal();
showModal
(<
LoadingModal
message=
"Ouverture de l'interface de paiement..."
/>);
log
.
info
(
"Url de paiement orange"
,
payment_url
);
log
.
info
(
"Url de paiement orange"
,
payment_url
);
log
.
info
(
"Ouverture du navigateur sur la page de paiement..."
);
log
.
info
(
"Ouverture du navigateur sur la page de paiement..."
);
await
handlePaymentUsingBrowser
(
payment_url
);
await
handlePaymentUsingBrowser
(
payment_url
);
log
.
info
(
"Verifying transaction status..."
);
log
.
info
(
"Verifying transaction status..."
);
showModal
(<
LoadingModal
message=
"Vérification du statut de la transaction..."
/>);
const
{
status
}
=
await
transactionsStatusMutation
.
mutateAsync
(
order_id
);
const
{
status
}
=
await
transactionsStatusMutation
.
mutateAsync
(
order_id
);
log
.
info
(
"result of transactions"
,
JSON
.
stringify
(
status
,
null
,
2
));
if
(
status
===
"SUCCESS"
)
{
log
.
info
(
"Transaction was a success, navigating to success page"
);
navigation
.
getParent
()?.
navigate
(
"paymentResultScreen"
);
navigation
.
getParent
()?.
navigate
(
"paymentResultScreen"
);
}
else
if
(
status
===
"FAILED"
)
{
}
catch
(
error
:
unknown
)
{
log
.
warn
(
"Transaction was a failed, navigating to error page"
);
log
.
error
(
"handlePaymentButton |"
,
error
);
}
else
if
(
status
===
"INITIATED"
)
{
if
(
error
instanceof
Error
)
{
log
.
warn
(
if
(
error
.
name
===
"ORANGE_PAYMENT_IN_PROGRESS"
)
{
"Transaction status was still 'INITIATED' after timeout, throwing an error"
,
log
.
warn
(
"handlePaymentButton | ORANGE_PAYMENT_IN_PROGRESS"
);
showModal
(
<
ErrorModal
message=
"Le payment est toujours en cours."
onPress=
{
closeModal
}
/>,
);
);
}
else
if
(
error
.
name
===
"ORANGE_PAYMENT_FAILED"
)
{
showModal
(<
ErrorModal
message=
"Le paiment à échoué."
onPress=
{
closeModal
}
/>);
log
.
error
(
"handlePaymentButton | ORANGE_PAYMENT_FAILED"
);
}
}
}
}
catch
(
error
)
{
log
.
error
(
"handlePaymentButton |"
,
error
);
//TODO : handle error
//TODO : handle error
}
}
},
[
amountToPay
,
orangeTransactionInitializerMutation
,
navigation
,
transactionsStatusMutation
,
handlePaymentUsingBrowser
,
closeModal
,
showModal
,
]);
const
handlePaymentButton
=
useCallback
(
async
()
=>
{
switch
(
paymentType
)
{
case
"OM"
:
{
Keyboard
.
dismiss
();
log
.
info
(
"OM so we stays on screen !!"
);
await
orangePaymentSequence
();
break
;
break
;
}
}
...
@@ -85,14 +109,7 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
...
@@ -85,14 +109,7 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
navigation
.
navigate
(
"numberAndOtpForPaymentScreen"
);
navigation
.
navigate
(
"numberAndOtpForPaymentScreen"
);
break
;
break
;
}
}
},
[
},
[
paymentType
,
navigation
,
orangePaymentSequence
]);
amountToPay
,
orangeTransactionInitializerMutation
,
paymentType
,
navigation
,
transactionsStatusMutation
,
handlePaymentUsingBrowser
,
]);
return
(
return
(
<
BackgroundDefault
>
<
BackgroundDefault
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment