forked from danrcoull/vsf-payment-braintree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
34 lines (29 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { StorefrontModule } from '@vue-storefront/core/lib/modules';
import { module } from './store'
import { coreHooks } from '@vue-storefront/core/hooks';
export const Braintree: StorefrontModule = function ({app, store, router, moduleConfig, appConfig}) {
store.registerModule('braintree', module);
coreHooks.afterAppInit(() => {
const CURRENT_METHOD_CODE = 'braintree'
store.dispatch('checkout/addPaymentMethod', {
'title': 'Braintree',
'code': CURRENT_METHOD_CODE,
'cost': 0,
'costInclTax': 0,
'default': true,
'offline': false
})
if (!app.$isServer) {
let isCurrentPaymentMethod = false
store.watch((state) => state.checkout.paymentDetails, (prevMethodCode, newMethodCode) => {
isCurrentPaymentMethod = newMethodCode.paymentMethod === CURRENT_METHOD_CODE
})
const invokePlaceOrder = () => {
if (isCurrentPaymentMethod) {
app.$emit('checkout-do-placeOrder', {})
}
}
app.$on('checkout-before-placeOrder', invokePlaceOrder)
}
})
}