-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PWA-2968::[Issue] Gomage/plugin braintree three d secure
- Loading branch information
Showing
10 changed files
with
310 additions
and
24 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
packages/extensions/gomage-plugin-braintree-three-d-secure/Intercepts/brainTreeDropIn.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
* adding to brainTreeDropIn 3D secure part | ||
* @param targets | ||
*/ | ||
function localIntercept(targets) { | ||
const {Targetables} = require('@magento/pwa-buildpack'); | ||
const targetables = Targetables.using(targets); | ||
|
||
/** | ||
* We can disable the logic if you will add to .env param CHECKOUT_BRAINTREE_3D with value false | ||
*/ | ||
if (process.env.CHECKOUT_BRAINTREE_3D != 'false') { | ||
const brainTreeDropIn = targetables.reactComponent( | ||
'@magento/venia-ui/lib/components/CheckoutPage/PaymentInformation/brainTreeDropIn.js' | ||
); | ||
|
||
/** | ||
* import 3d secure plugin | ||
*/ | ||
brainTreeDropIn.addImport('{useBraintreeThreeDSecure} from "@gomage/plugin-braintree-three-d-secure"'); | ||
brainTreeDropIn.addImport('{usePriceSummary} from "@magento/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary"'); | ||
|
||
/** | ||
* add hook for getting of client token | ||
*/ | ||
brainTreeDropIn.insertAfterSource( | ||
'const [dropinInstance, setDropinInstance] = useState();', | ||
'\n const clientToken = useBraintreeThreeDSecure();' + | ||
'\n const talonProps = usePriceSummary();' | ||
); | ||
/** | ||
* check if exist clientToken | ||
*/ | ||
brainTreeDropIn.insertAfterSource( | ||
'const createDropinInstance = useCallback(async () => {', | ||
'\n if(clientToken){ ' | ||
); | ||
/** | ||
* end condition of check if exist clientToken | ||
*/ | ||
brainTreeDropIn.insertAfterSource( | ||
'return dropinInstance;', | ||
'\n}' | ||
); | ||
/** | ||
* setting new dependency clientToken to useCallback createDropinInstance hook | ||
*/ | ||
brainTreeDropIn.insertAfterSource( | ||
'[containerId', | ||
' ,clientToken, talonProps.flatData.total.value' | ||
); | ||
|
||
|
||
/** | ||
* check if exist clientToken | ||
*/ | ||
brainTreeDropIn.insertBeforeSource( | ||
'const renderDropin = async () => {', | ||
'\n if(clientToken){ ' | ||
); | ||
|
||
/** | ||
* end condition of check if exist clientToken | ||
*/ | ||
brainTreeDropIn.insertBeforeSource( | ||
'}, [createDropinInstance, onReady]);', | ||
'} \n' | ||
); | ||
|
||
/** | ||
* setting new dependency clientToken to useEffect hook | ||
*/ | ||
brainTreeDropIn.insertAfterSource( | ||
'[createDropinInstance, onReady', | ||
' ,clientToken' | ||
); | ||
|
||
|
||
/** | ||
* change of value token to client Token | ||
*/ | ||
brainTreeDropIn.insertAfterSource( | ||
'const dropinInstance = await dropIn.create({\n' + | ||
' authorization', | ||
':clientToken', | ||
); | ||
|
||
/** | ||
* enable 3d secure | ||
*/ | ||
brainTreeDropIn.insertAfterSource( | ||
'container: `#${containerId}`,', | ||
'\n threeDSecure: {amount:talonProps.flatData.total.value},', | ||
); | ||
|
||
/** | ||
* update brain tree if total was changes | ||
*/ | ||
brainTreeDropIn.insertBeforeSource( | ||
'if (isError) {', | ||
'useEffect(() => {\n' + | ||
' if(dropinInstance) {\n' + | ||
' dropinInstance.teardown();\n' + | ||
' }\n' + | ||
' }, [\n' + | ||
' talonProps.flatData.total.value,\n' + | ||
']);', | ||
); | ||
} | ||
} | ||
|
||
module.exports = localIntercept; |
22 changes: 22 additions & 0 deletions
22
packages/extensions/gomage-plugin-braintree-three-d-secure/Model/useBraintreeThreeDSecure.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {useMutation} from "@apollo/client"; | ||
import {useEffect} from "react"; | ||
import {GET_BRAINTREE_CLIENT_TOKEN} from '../Queries/createBraintreeClientToken.gql'; | ||
|
||
/** | ||
* | ||
* @returns {*|string} | ||
*/ | ||
export const useBraintreeThreeDSecure = () => { | ||
const [setBraintreeClientToken, {data}] = useMutation(GET_BRAINTREE_CLIENT_TOKEN); | ||
const clientToken = data ? data.createBraintreeClientToken : ''; | ||
/** | ||
* set Braintree Client Token | ||
*/ | ||
useEffect(() => { | ||
if(!clientToken) { | ||
setBraintreeClientToken(); | ||
} | ||
}, []); | ||
|
||
return clientToken; | ||
} |
10 changes: 10 additions & 0 deletions
10
...tensions/gomage-plugin-braintree-three-d-secure/Queries/createBraintreeClientToken.gql.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { gql } from '@apollo/client'; | ||
/** | ||
* | ||
* @type {DocumentNode} | ||
*/ | ||
export const GET_BRAINTREE_CLIENT_TOKEN = gql` | ||
mutation { | ||
createBraintreeClientToken | ||
} | ||
`; |
7 changes: 7 additions & 0 deletions
7
packages/extensions/gomage-plugin-braintree-three-d-secure/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# GoMage Braintree 3D Secure | ||
|
||
GoMage Braintree 3D Secure | ||
|
||
That plugin works only as a fix bugs of PWA Studio and adds 3d secure part. | ||
|
||
If you need to disable the module, you can add to the .env parameter CHECKOUT_BRAINTREE_3D=false, or remove the plugin. |
1 change: 1 addition & 0 deletions
1
packages/extensions/gomage-plugin-braintree-three-d-secure/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {useBraintreeThreeDSecure} from './Model/useBraintreeThreeDSecure' |
9 changes: 9 additions & 0 deletions
9
packages/extensions/gomage-plugin-braintree-three-d-secure/intercept.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* | ||
* @param targets | ||
*/ | ||
function localIntercept(targets) { | ||
require("@gomage/plugin-braintree-three-d-secure/Intercepts/brainTreeDropIn")(targets); | ||
} | ||
|
||
module.exports = localIntercept; |
15 changes: 15 additions & 0 deletions
15
packages/extensions/gomage-plugin-braintree-three-d-secure/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@gomage/plugin-braintree-three-d-secure", | ||
"version": "1.0.3", | ||
"description": "GoMage Braintree 3D Secure", | ||
"main": "./index.js", | ||
"author": "GoMage", | ||
"pwa-studio": { | ||
"targets": { | ||
"intercept": "./intercept.js" | ||
} | ||
}, | ||
"dependencies": { | ||
"braintree-web-drop-in": "~1.33.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,10 @@ | |
"pwa-studio": { | ||
"targets": { | ||
"intercept": "./local-intercept.js" | ||
} | ||
}, | ||
"trusted-vendors": [ | ||
"@gomage" | ||
] | ||
} | ||
|
||
} |
Oops, something went wrong.