diff --git a/packages/api-client/src/api/index.ts b/packages/api-client/src/api/index.ts index 88daa794..65422925 100644 --- a/packages/api-client/src/api/index.ts +++ b/packages/api-client/src/api/index.ts @@ -10,6 +10,7 @@ export { default as removeCartCoupon } from './removeCartCoupon'; export { default as getMe } from './getMe'; export { default as updateAddressDetails } from './updateAddressDetails'; export { default as getShippingMethods } from './getShippingMethods'; +export { default as getPaymentMethods } from './getPaymentMethods'; export { default as setShippingMethod } from './setShippingMethod'; export { default as setPaymentMethod } from './setPaymentMethod'; export { default as transitionOrderToState } from './transitionOrderToState'; diff --git a/packages/composables/src/getters/cartGetters.ts b/packages/composables/src/getters/cartGetters.ts index f65cfc13..efcec718 100644 --- a/packages/composables/src/getters/cartGetters.ts +++ b/packages/composables/src/getters/cartGetters.ts @@ -14,7 +14,7 @@ interface ExtendedCartGetters extends CartGetters { } const getItems = (cart: Order): OrderLine[] => { - if (!cart.lines) return []; + if (!cart?.lines) return []; return cart?.lines; }; diff --git a/packages/theme/components/Checkout/VsfPaymentProvider.vue b/packages/theme/components/Checkout/VsfPaymentProvider.vue index a12b7048..604d9788 100644 --- a/packages/theme/components/Checkout/VsfPaymentProvider.vue +++ b/packages/theme/components/Checkout/VsfPaymentProvider.vue @@ -43,8 +43,9 @@ import { SfButton, SfRadio } from '@storefront-ui/vue'; -import { ref } from '@vue/composition-api'; +import { ref, onMounted } from '@vue/composition-api'; import { usePaymentProviderMock } from '@/composables/usePaymentProviderMock'; +import { useVSFContext } from '@vue-storefront/core'; export default { name: 'VsfPaymentProvider', @@ -53,22 +54,24 @@ export default { SfButton, SfRadio }, - setup () { + setup (_, { emit }) { const { status } = usePaymentProviderMock(); const selectedPaymentMethod = ref({}); - const paymentMethods = ref([ - { - id: 'mocked-id', - name: 'Cash on delivery', - description: '' - } - ]); + const { $vendure } = useVSFContext(); + const paymentMethods = ref([]); - const selectPaymentMethod = paymentMethod => { + const selectPaymentMethod = async (paymentMethod) => { selectedPaymentMethod.value = paymentMethod; + emit('paymentMethodSelected', paymentMethod); status.value = true; }; + onMounted(async () => { + const response = await $vendure.api.getPaymentMethods(); + + paymentMethods.value = response?.data?.eligiblePaymentMethods; + }); + return { paymentMethods, selectedPaymentMethod, diff --git a/packages/theme/pages/Checkout/Payment.vue b/packages/theme/pages/Checkout/Payment.vue index 4dd9816a..b45dbd20 100644 --- a/packages/theme/pages/Checkout/Payment.vue +++ b/packages/theme/pages/Checkout/Payment.vue @@ -63,7 +63,7 @@ class="sf-property--full-width sf-property--large summary__property-total" /> - +