Skip to content

Commit

Permalink
feat: #56 (*) move metadata to api client
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Aug 25, 2021
1 parent 46d9fa5 commit b6eebed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
11 changes: 8 additions & 3 deletions packages/api-client/src/api/setPaymentMethod/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import addPaymentToOrderMutation from './addPaymentToOrderMutation';
import { CustomQuery } from '@vue-storefront/core';
import gql from 'graphql-tag';
import { Context, PaymentInput, SetShippingMethodResponse } from '../../types';
import { AddPaymentToOrderParams, Context, PaymentInput, SetShippingMethodResponse } from '../../types';

const setPaymentMethod = async (context: Context, params: PaymentInput, customQuery?: CustomQuery): Promise<SetShippingMethodResponse> => {
const setPaymentMethod = async (context: Context, params: AddPaymentToOrderParams, customQuery?: CustomQuery): Promise<SetShippingMethodResponse> => {
const setPaymentMethodVariables = {
input: params
input: {
method: params.method,
metadata: {
// Here you would pass data from an external Payment Provided after successful payment process like payment id.
}
} as PaymentInput,
};

const { addPaymentToOrder } = context.extendQuery(
Expand Down
6 changes: 3 additions & 3 deletions packages/api-client/src/types/API.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CustomQuery } from '@vue-storefront/core';
import { ApolloQueryResult } from 'apollo-client';
import { FetchResult } from 'apollo-link';
import { ActiveOrderResult, ApplyCouponCodeResult, CollectionList, CreateCustomerInput, Customer, Order, PaymentInput, PaymentMethodQuote, Product, RemoveOrderItemsResult, SearchResponse, SetCustomerForOrderResult, ShippingMethodQuote, UpdateOrderItemsResult } from './GraphQL';
import { AddToCartParams, CartCouponParams, CollectionParams, ProductParams, RemoveFromCartParams, SearchParams, SetShippingMethodParams, TransitionOrderToStateParams, UpdateAddressDetailsParams, UpdateCartParams } from './types';
import { ActiveOrderResult, ApplyCouponCodeResult, CollectionList, CreateCustomerInput, Customer, Order, PaymentMethodQuote, Product, RemoveOrderItemsResult, SearchResponse, SetCustomerForOrderResult, ShippingMethodQuote, UpdateOrderItemsResult } from './GraphQL';
import { AddPaymentToOrderParams, AddToCartParams, CartCouponParams, CollectionParams, ProductParams, RemoveFromCartParams, SearchParams, SetShippingMethodParams, TransitionOrderToStateParams, UpdateAddressDetailsParams, UpdateCartParams } from './types';

export type QueryResponse<K extends string, V> = ApolloQueryResult<Record<K, V>>;
export type MutationResponse<K extends string, V> = FetchResult<Record<K, V>>;
Expand Down Expand Up @@ -41,7 +41,7 @@ export interface VendureApiMethods {
removeCouponCode(params: CartCouponParams, customQuery?: CustomQuery): Promise<RemoveCouponCodeResponse>;
updateAddressDetails(params: UpdateAddressDetailsParams, customQuery?: CustomQuery): Promise<UpdateAddressDetailsResponse>;
setShippingMethod(params: SetShippingMethodParams, customQuery?: CustomQuery): Promise<SetShippingMethodResponse>;
setPaymentMethod(params: PaymentInput, customQuery?: CustomQuery): Promise<SetPaymentMethodResponse>;
setPaymentMethod(params: AddPaymentToOrderParams, customQuery?: CustomQuery): Promise<SetPaymentMethodResponse>;
transitionOrderToState(params: TransitionOrderToStateParams, customQuery?: CustomQuery): Promise<TransitionOrderToState>;
setCustomerForOrder(params: CreateCustomerInput, customQuery?: CustomQuery): Promise<SetCustomerForOrderResponse>;
}
8 changes: 6 additions & 2 deletions packages/api-client/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ export type UpdateAddressDetailsParams = {

export type SetShippingMethodParams = {
shippingMethodId: string;
}
};

export type TransitionOrderToStateParams = {
state: string;
}
};

export type AddPaymentToOrderParams = {
method: string;
};
3 changes: 0 additions & 3 deletions packages/theme/pages/Checkout/Payment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ export default {
const processOrder = async () => {
const response = await $vendure.api.setPaymentMethod({
method: paymentMethod?.value?.code,
metadata: {
// Here goes metadata from the payment provider. For security reasons it should be handled on the server!
}
});
const orderId = response?.data?.addPaymentToOrder?.id;
Expand Down

0 comments on commit b6eebed

Please sign in to comment.