payment-helpers.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { ID } from '@vendure/common/lib/shared-types';
  2. import { SimpleGraphQLClient } from '@vendure/testing';
  3. import { REFUND_ORDER } from './graphql/admin-queries';
  4. import { RefundFragment, RefundOrder } from './graphql/generated-admin-types';
  5. import {
  6. GetShippingMethods,
  7. SetShippingMethod,
  8. TestOrderFragmentFragment,
  9. TransitionToState,
  10. } from './graphql/generated-shop-types';
  11. import {
  12. GET_ELIGIBLE_SHIPPING_METHODS,
  13. SET_SHIPPING_ADDRESS,
  14. SET_SHIPPING_METHOD,
  15. TRANSITION_TO_STATE,
  16. } from './graphql/shop-queries';
  17. export async function setShipping(shopClient: SimpleGraphQLClient): Promise<void> {
  18. await shopClient.query(SET_SHIPPING_ADDRESS, {
  19. input: {
  20. fullName: 'name',
  21. streetLine1: '12 the street',
  22. city: 'foo',
  23. postalCode: '123456',
  24. countryCode: 'US',
  25. },
  26. });
  27. const { eligibleShippingMethods } = await shopClient.query<GetShippingMethods.Query>(
  28. GET_ELIGIBLE_SHIPPING_METHODS,
  29. );
  30. await shopClient.query<SetShippingMethod.Mutation, SetShippingMethod.Variables>(SET_SHIPPING_METHOD, {
  31. id: eligibleShippingMethods[1].id,
  32. });
  33. }
  34. export async function proceedToArrangingPayment(shopClient: SimpleGraphQLClient): Promise<ID> {
  35. await setShipping(shopClient);
  36. const { transitionOrderToState } = await shopClient.query<
  37. TransitionToState.Mutation,
  38. TransitionToState.Variables
  39. >(TRANSITION_TO_STATE, { state: 'ArrangingPayment' });
  40. // tslint:disable-next-line:no-non-null-assertion
  41. return (transitionOrderToState as TestOrderFragmentFragment)!.id;
  42. }
  43. export async function refundOne(
  44. adminClient: SimpleGraphQLClient,
  45. orderLineId: string,
  46. paymentId: string,
  47. ): Promise<RefundFragment> {
  48. const { refundOrder } = await adminClient.query<RefundOrder.Mutation, RefundOrder.Variables>(
  49. REFUND_ORDER,
  50. {
  51. input: {
  52. lines: [{ orderLineId, quantity: 1 }],
  53. shipping: 0,
  54. adjustment: 0,
  55. paymentId,
  56. },
  57. },
  58. );
  59. return refundOrder as RefundFragment;
  60. }