Skip to content

Commit

Permalink
Merge pull request #289 from Pinelab-studio/feat/mollie-vendure-order…
Browse files Browse the repository at this point in the history
…-client

Mollie Vendure Order Client
  • Loading branch information
martijnvdbrug authored Nov 9, 2023
2 parents 324ccec + 23b27c2 commit 91269e3
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 328 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
"@types/sharp": "0.28.0",
"@types/tmp": "0.2.3",
"@typescript-eslint/eslint-plugin": "5.43.0",
"@vendure/admin-ui-plugin": "2.1.1",
"@vendure/asset-server-plugin": "2.1.1",
"@vendure/core": "2.1.1",
"@vendure/email-plugin": "2.1.1",
"@vendure/testing": "2.1.1",
"@vendure/ui-devkit": "2.1.1",
"@vendure/admin-ui-plugin": "2.1.2",
"@vendure/asset-server-plugin": "2.1.2",
"@vendure/core": "2.1.2",
"@vendure/email-plugin": "2.1.2",
"@vendure/testing": "2.1.2",
"@vendure/ui-devkit": "2.1.2",
"@vendure/payments-plugin": "2.1.2",
"aws-sdk": "2.1099.0",
"copyfiles": "2.4.1",
"eslint": "8.0.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/vendure-order-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.4.0 (2023-11-09)

- Add mollie payment intent creation vendure client
- Updated vendure to 2.1.2

# 2.3.0 (2023-10-24)

- Updated vendure to 2.1.1
Expand Down
5 changes: 3 additions & 2 deletions packages/vendure-order-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pinelab/vendure-order-client",
"version": "2.3.0",
"version": "2.4.0",
"description": "A tiny, framework agnostic client for managing active orders and checkout with Vendure.",
"author": "Martijn van de Brug <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down Expand Up @@ -34,7 +34,8 @@
},
"devDependencies": {
"@nanostores/vue": "^0.10.0",
"@vue/cli": "^5.0.8"
"@vue/cli": "^5.0.8",
"@mollie/api-client": "3.7.0"
},
"gitHead": "476f36da3aafea41fbf21c70774a30306f1d238f"
}
10 changes: 10 additions & 0 deletions packages/vendure-order-client/src/graphql-generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ export interface BooleanOperators {
isNull?: InputMaybe<Scalars['Boolean']>;
}

export interface MutationCreateMolliePaymentIntentArgs {
input: MolliePaymentIntentInput;
}

export interface MolliePaymentIntentInput {
molliePaymentMethodCode?: InputMaybe<Scalars['String']>;
paymentMethodCode: Scalars['String'];
redirectUrl?: InputMaybe<Scalars['String']>;
}

export type Channel = Node & {
__typename?: 'Channel';
availableCurrencyCodes: CurrencyCode[];
Expand Down
16 changes: 16 additions & 0 deletions packages/vendure-order-client/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,20 @@ export class GraphqlQueries {
}
}
`;

CREATE_MOLLIE_PAYMENT_INTENT = gql`
mutation CreateMolliPaymentIntentMutation(
$input: MolliePaymentIntentInput!
) {
createMolliePaymentIntent(input: $input) {
... on MolliePaymentIntent {
url
}
... on MolliePaymentIntentError {
errorCode
message
}
}
}
`;
}
15 changes: 15 additions & 0 deletions packages/vendure-order-client/src/vendure-order-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
Success,
TransitionOrderToStateMutation,
ShippingMethodQuote,
MolliePaymentIntentInput,
MutationCreateMolliePaymentIntentArgs,
} from './graphql-generated-types';
import { GraphqlQueries } from './queries';
import { setResult, HandleLoadingState, StateStore } from './store-helpers';
Expand Down Expand Up @@ -336,6 +338,19 @@ export class VendureOrderClient<A = unknown> {
return activeOrder;
}

async createMolliePaymentIntent(
input: MolliePaymentIntentInput
): Promise<string> {
const { createMolliePaymentIntent } = await this.rawRequest<
any,
MutationCreateMolliePaymentIntentArgs
>(this.queries.CREATE_MOLLIE_PAYMENT_INTENT, { input });
const molliePaymentLink = this.throwIfErrorResult<string>(
createMolliePaymentIntent
);
return molliePaymentLink;
}

@HandleLoadingState('$activeOrder')
async transitionOrderToState(
state: string
Expand Down
5 changes: 5 additions & 0 deletions packages/vendure-order-client/test/initial-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LanguageCode } from '@vendure/common/lib/generated-types.js';
import { InitialData } from '@vendure/core';
import { testPaymentMethodHandler } from './test-payment-method-handler.js';
import { molliePaymentHandler } from '@vendure/payments-plugin/package/mollie/mollie.handler';

export const initialData: InitialData = {
defaultLanguage: LanguageCode.en,
Expand Down Expand Up @@ -40,5 +41,9 @@ export const initialData: InitialData = {
handler: { code: testPaymentMethodHandler.code, arguments: [] },
name: 'Test payment',
},
{
handler: { code: molliePaymentHandler.code, arguments: [] },
name: 'Mollie Payment',
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ export const testPaymentMethodHandler = new PaymentMethodHandler({
success: true,
}),
});

// export const testPaymentMethod= new PaymentMethod()
51 changes: 48 additions & 3 deletions packages/vendure-order-client/test/vendure-order-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import {
ActiveOrderFieldsFragment,
CreateAddressInput,
CreateCustomerInput,
MolliePaymentIntentInput,
PaymentInput,
RegisterCustomerInput,
Success,
} from '../src/graphql-generated-types';
import { initialData } from './initial-data';
import { testPaymentMethodHandler } from './test-payment-method-handler';
import { useStore } from '@nanostores/vue';
import { MapStore, listenKeys } from 'nanostores';
import { molliePaymentHandler } from '@vendure/payments-plugin/package/mollie/mollie.handler';
import { MolliePlugin } from '@vendure/payments-plugin/package/mollie/mollie.plugin';

const storage: any = {};
const window = {
Expand Down Expand Up @@ -66,8 +70,17 @@ describe(
beforeAll(async () => {
registerInitializer('sqljs', new SqljsInitializer('__data__'));
const config = mergeConfig(testConfig, {
plugins: [
MolliePlugin.init({
vendureHost: 'my-vendure.io',
useDynamicRedirectUrl: true,
}),
],
paymentOptions: {
paymentMethodHandlers: [testPaymentMethodHandler],
paymentMethodHandlers: [
testPaymentMethodHandler,
molliePaymentHandler,
],
},
authOptions: {
requireVerification: false,
Expand Down Expand Up @@ -479,9 +492,11 @@ describe(
});

describe('Registered customer checkout', () => {
const createNewCustomerInput = {
const createNewCustomerInput: RegisterCustomerInput = {
emailAddress: `test${Math.random()}@xyz.com`,
password: '1qaz2wsx',
firstName: 'Hans',
lastName: 'Miller',
};
/* */
it('Register as customer', async () => {
Expand All @@ -496,7 +511,7 @@ describe(
async () =>
await client.login(
createNewCustomerInput.emailAddress,
createNewCustomerInput.password
createNewCustomerInput.password as string
)
);
expect(currentUserStore.value.data.identifier).toBe(
Expand All @@ -518,6 +533,36 @@ describe(
'T_1'
);
});
it('Should create mollie payment intent as authenticated customer', async () => {
await client.addItemToOrder('T_1', 1);
await client.setCustomerForOrder({
emailAddress: createNewCustomerInput.emailAddress,
firstName: createNewCustomerInput.firstName as string,
lastName: createNewCustomerInput.lastName as string,
});
await client.setOrderShippingAddress({
fullName: 'name',
streetLine1: '12 the street',
city: 'Leeuwarden',
postalCode: '123456',
countryCode: 'AT',
});
await client.setOrderShippingMethod([
client.$eligibleShippingMethods.value?.data?.[0]?.id as string,
]);
const createMolliPaymentIntentInput: MolliePaymentIntentInput = {
redirectUrl: 'https://remix-storefront.vendure.io',
paymentMethodCode: 'mollie-payment',
molliePaymentMethodCode: 'ideal',
};
try {
await client.createMolliePaymentIntent(createMolliPaymentIntentInput);
} catch (e) {
expect(e.message).toBe(
'Paymentmethod mollie-payment has no apiKey configured'
);
}
});
});

afterAll(async () => {
Expand Down
Loading

0 comments on commit 91269e3

Please sign in to comment.