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
c23ccfd6
Commit
c23ccfd6
authored
May 14, 2024
by
G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create a separate hook to handle the logic of the payment through orange money
parent
23a83c2b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
2 deletions
+49
-2
useOrangeMoney.tsx
src/hooks/useOrangeMoney.tsx
+44
-0
PaymentAmountInputScreen.tsx
src/screens/PaymentAmountInputScreen.tsx
+5
-2
No files found.
src/hooks/useOrangeMoney.tsx
0 → 100644
View file @
c23ccfd6
import
{
type
IorangePaymentStarter
,
getTransactionsData
}
from
"@/utils/requests/orangePayment"
;
import
{
useMutation
}
from
"@tanstack/react-query"
;
import
*
as
WebBrowser
from
"expo-web-browser"
;
import
{
useState
}
from
"react"
;
const
paymentObjectDefault
:
IorangePaymentStarter
=
{
// biome-ignore lint/style/useNamingConvention: <api expect type_paiement>
type_paiement
:
1
,
marchand
:
"1"
,
service
:
"1"
,
montant
:
0
,
numero
:
"0707070707"
,
commentaire
:
"Un commentaire"
,
};
const
useOrangeMoney
=
()
=>
{
const
[
isBrowserOpen
,
setIsBrowserOpen
]
=
useState
(
false
);
const
handlePaymentUsingBrowser
=
async
(
url
:
string
)
=>
{
const
result
=
await
WebBrowser
.
openBrowserAsync
(
url
);
// setResult(result);
console
.
log
(
"result"
,
result
);
};
const
omPaymentMutation
=
useMutation
({
mutationFn
:
(
amount
:
number
)
=>
getTransactionsData
({
// biome-ignore lint/style/useNamingConvention: <explanation>
...
paymentObjectDefault
,
montant
:
amount
,
}),
onSuccess
:
async
(
data
)
=>
{
await
handlePaymentUsingBrowser
(
data
.
payment_url
);
// setResult(result);
},
onError
:
(
err
)
=>
{
console
.
log
(
"om start error "
,
err
);
},
});
return
{
omPaymentMutation
,
isBrowserOpen
};
};
export
default
useOrangeMoney
;
src/screens/PaymentAmountInputScreen.tsx
View file @
c23ccfd6
...
@@ -8,6 +8,7 @@ import PaymentOption from "@components/PaymentOption";
...
@@ -8,6 +8,7 @@ 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
useOrangeMoney
from
"@hooks/useOrangeMoney"
;
import
{
useMutation
}
from
"@tanstack/react-query"
;
import
{
useMutation
}
from
"@tanstack/react-query"
;
import
*
as
WebBrowser
from
"expo-web-browser"
;
import
*
as
WebBrowser
from
"expo-web-browser"
;
import
{
useCallback
,
useState
}
from
"react"
;
import
{
useCallback
,
useState
}
from
"react"
;
...
@@ -20,6 +21,8 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
...
@@ -20,6 +21,8 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
const
{
paymentType
}
=
route
.
params
;
const
{
paymentType
}
=
route
.
params
;
const
[
amountToPay
,
setAmountToPay
]
=
useState
(
0
);
const
[
amountToPay
,
setAmountToPay
]
=
useState
(
0
);
const
{
omPaymentMutation
:
orangePaymentMutation
}
=
useOrangeMoney
();
const
insets
=
useSafeAreaInsets
();
const
insets
=
useSafeAreaInsets
();
const
updateAmountToPay
=
(
amount
:
string
)
=>
{
const
updateAmountToPay
=
(
amount
:
string
)
=>
{
...
@@ -76,13 +79,13 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
...
@@ -76,13 +79,13 @@ const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountI
case
"OM"
:
case
"OM"
:
console
.
log
(
"OM so we stays on screen !!"
);
console
.
log
(
"OM so we stays on screen !!"
);
console
.
log
(
"Calling api with amount :: "
,
amountToPay
);
console
.
log
(
"Calling api with amount :: "
,
amountToPay
);
o
m
PaymentMutation
.
mutate
(
amountToPay
);
o
range
PaymentMutation
.
mutate
(
amountToPay
);
break
;
break
;
default
:
default
:
navigation
.
navigate
(
"numberAndOtpForPaymentScreen"
);
navigation
.
navigate
(
"numberAndOtpForPaymentScreen"
);
break
;
break
;
}
}
},
[
amountToPay
,
o
m
PaymentMutation
,
paymentType
,
navigation
]);
},
[
amountToPay
,
o
range
PaymentMutation
,
paymentType
,
navigation
]);
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