Skip to content

Commit

Permalink
feat(core): Allow public & private Payment metadata
Browse files Browse the repository at this point in the history
Closes #476

BREAKING CHANGE: The `Payment.metadata` field is not private by default, meaning that it can only be read via the Admin API. Data required in the Shop API can be accessed by putting it in a field named `public`. Example: `Payment.metadata.public.redirectUrl`
  • Loading branch information
michaelbromley committed Oct 6, 2020
1 parent d280466 commit 3f72311
Show file tree
Hide file tree
Showing 19 changed files with 463 additions and 273 deletions.
11 changes: 10 additions & 1 deletion docs/content/docs/developer-guide/payment-integrations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ const myPaymentIntegration = new PaymentMethodHandler({
amount: order.total,
state: 'Authorized' as const,
transactionId: result.id.toString(),
metadata: result.outcome,
metadata: {
cardInfo: result.cardInfo,
// Any metadata in the `public` field
// will be available in the Shop API,
// All other metadata is private and
// only available in the Admin API.
public: {
referenceCode: result.publicId,
}
},
};
} catch (err) {
return {
Expand Down
22 changes: 22 additions & 0 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4396,6 +4396,20 @@ export type GetUiStateQuery = { uiState: (
& Pick<UiState, 'language'>
) };

export type GetClientStateQueryVariables = Exact<{ [key: string]: never; }>;


export type GetClientStateQuery = { networkStatus: (
{ __typename?: 'NetworkStatus' }
& Pick<NetworkStatus, 'inFlightRequests'>
), userStatus: (
{ __typename?: 'UserStatus' }
& UserStatusFragment
), uiState: (
{ __typename?: 'UiState' }
& Pick<UiState, 'language'>
) };

export type SetActiveChannelMutationVariables = Exact<{
channelId: Scalars['ID'];
}>;
Expand Down Expand Up @@ -7077,6 +7091,14 @@ export namespace GetUiState {
export type UiState = (NonNullable<GetUiStateQuery['uiState']>);
}

export namespace GetClientState {
export type Variables = GetClientStateQueryVariables;
export type Query = GetClientStateQuery;
export type NetworkStatus = (NonNullable<GetClientStateQuery['networkStatus']>);
export type UserStatus = (NonNullable<GetClientStateQuery['userStatus']>);
export type UiState = (NonNullable<GetClientStateQuery['uiState']>);
}

export namespace SetActiveChannel {
export type Variables = SetActiveChannelMutationVariables;
export type Mutation = SetActiveChannelMutation;
Expand Down
19 changes: 15 additions & 4 deletions packages/core/e2e/fixtures/test-payment-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const testSuccessfulPaymentMethod = new PaymentMethodHandler({
amount: order.total,
state: 'Settled',
transactionId: '12345',
metadata,
metadata: { public: metadata },
};
},
settlePayment: order => ({
Expand All @@ -32,7 +32,7 @@ export const twoStagePaymentMethod = new PaymentMethodHandler({
amount: order.total,
state: 'Authorized',
transactionId: '12345',
metadata,
metadata: { public: metadata },
};
},
settlePayment: () => {
Expand Down Expand Up @@ -87,13 +87,24 @@ export const failsToSettlePaymentMethod = new PaymentMethodHandler({
amount: order.total,
state: 'Authorized',
transactionId: '12345',
metadata,
metadata: {
privateCreatePaymentData: 'secret',
public: {
publicCreatePaymentData: 'public',
},
},
};
},
settlePayment: () => {
return {
success: false,
errorMessage: 'Something went horribly wrong',
metadata: {
privateSettlePaymentData: 'secret',
public: {
publicSettlePaymentData: 'public',
},
},
};
},
});
Expand All @@ -106,7 +117,7 @@ export const testFailingPaymentMethod = new PaymentMethodHandler({
amount: order.total,
state: 'Declined',
errorMessage: 'Insufficient funds',
metadata,
metadata: { public: metadata },
};
},
settlePayment: order => ({
Expand Down
Loading

0 comments on commit 3f72311

Please sign in to comment.