mollie-dev-server.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
  2. import { DefaultLogger, DefaultSearchPlugin, LanguageCode, LogLevel, mergeConfig } from '@vendure/core';
  3. import { createTestEnvironment, registerInitializer, SqljsInitializer, testConfig } from '@vendure/testing';
  4. import gql from 'graphql-tag';
  5. import localtunnel from 'localtunnel';
  6. import path from 'path';
  7. import { initialData } from '../../../e2e-common/e2e-initial-data';
  8. import { molliePaymentHandler } from '../package/mollie/mollie.handler';
  9. import { MolliePlugin } from '../src/mollie';
  10. import { CREATE_PAYMENT_METHOD } from './graphql/admin-queries';
  11. import { ADD_ITEM_TO_ORDER, APPLY_COUPON_CODE } from './graphql/shop-queries';
  12. import { setShipping } from './payment-helpers';
  13. /**
  14. * This should only be used to locally test the Mollie payment plugin
  15. * Make sure you have `MOLLIE_APIKEY=test_xxxx` in your .env file
  16. */
  17. /* eslint-disable @typescript-eslint/no-floating-promises */
  18. async function runMollieDevServer() {
  19. // eslint-disable-next-line @typescript-eslint/no-var-requires
  20. require('dotenv').config();
  21. registerInitializer('sqljs', new SqljsInitializer(path.join(__dirname, '__data__')));
  22. const tunnel = await localtunnel({ port: 3050 });
  23. const config = mergeConfig(testConfig, {
  24. plugins: [
  25. ...testConfig.plugins,
  26. DefaultSearchPlugin,
  27. AdminUiPlugin.init({
  28. route: 'admin',
  29. port: 5001,
  30. }),
  31. MolliePlugin.init({ vendureHost: tunnel.url }),
  32. ],
  33. logger: new DefaultLogger({ level: LogLevel.Debug }),
  34. apiOptions: {
  35. adminApiPlayground: true,
  36. shopApiPlayground: true,
  37. },
  38. });
  39. const { server, shopClient, adminClient } = createTestEnvironment(config as any);
  40. await server.init({
  41. initialData,
  42. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  43. customerCount: 1,
  44. });
  45. // Set EUR as currency for Mollie
  46. await adminClient.asSuperAdmin();
  47. await adminClient.query(gql`
  48. mutation {
  49. updateChannel(input: { id: "T_1", currencyCode: EUR }) {
  50. __typename
  51. }
  52. }
  53. `);
  54. // Create method
  55. await adminClient.query(CREATE_PAYMENT_METHOD, {
  56. input: {
  57. code: 'mollie',
  58. translations: [
  59. {
  60. languageCode: LanguageCode.en,
  61. name: 'Mollie payment test',
  62. description: 'This is a Mollie test payment method',
  63. },
  64. ],
  65. enabled: true,
  66. handler: {
  67. code: molliePaymentHandler.code,
  68. arguments: [
  69. {
  70. name: 'redirectUrl',
  71. value: `${tunnel.url}/admin/orders?filter=open&page=1`,
  72. },
  73. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  74. { name: 'apiKey', value: process.env.MOLLIE_APIKEY! },
  75. ],
  76. },
  77. },
  78. });
  79. // Prepare a test order where the total is 0
  80. await shopClient.asUserWithCredentials('hayden.zieme12@hotmail.com', 'test');
  81. await shopClient.query(ADD_ITEM_TO_ORDER, {
  82. productVariantId: 'T_1',
  83. quantity: 1,
  84. });
  85. await setShipping(shopClient);
  86. await shopClient.query(APPLY_COUPON_CODE, { couponCode: 'FREE_SHIPPING' });
  87. // Create Payment Intent
  88. const result = await shopClient.query(CREATE_MOLLIE_PAYMENT_INTENT, {
  89. input: {
  90. locale: 'nl_NL',
  91. immediateCapture: false,
  92. },
  93. });
  94. // eslint-disable-next-line no-console
  95. console.log('Payment intent result', result);
  96. // Uncomme this line to disable webhook processing and test the `syncMolliePaymentStatus` mutation
  97. // MolliePlugin.options.disableWebhookProcessing = true;
  98. }
  99. (async () => {
  100. await runMollieDevServer();
  101. })();
  102. const CREATE_MOLLIE_PAYMENT_INTENT = gql`
  103. mutation createMolliePaymentIntent($input: MolliePaymentIntentInput!) {
  104. createMolliePaymentIntent(input: $input) {
  105. ... on MolliePaymentIntent {
  106. url
  107. }
  108. }
  109. }
  110. `;