ycs-plugin-payments
TypeScript icon, indicating that this package has built-in type declarations

0.5.12 • Public • Published

Build Status Coverage Status MIT license

Installation

ycs add plugin payments

configurations

import { IContext } from '@ycs/core/lib/context';
import { IConfig, EChannel, ECurrency, IChargeDocument } from 'ycs-plugin-payments';
import { Client, EClientSignType } from '@ycnt/alipay';
 
export const development: IConfig = {
  roles: ['payments'],
  payments: [
    {
      path: 'order',
      channels: [EChannel.alipay],
      currencies: [ECurrency.cny],
      charge: async (ctx: IContext): Promise<IChargeDocument> => {
        const order: any = 'xxx';
        return {
          channel: ctx.request.fields.channel,
          currency: ECurrency.cny,
          client_ip: ctx.request.ip,
          subject: order.subject,
          body: order.body,
          amount: order.price,
          extra: {
            orderId: order._id,
          },
          __auth: ctx.request.auth._id,
        };
      },
      webhook: async (doc: IChargeDocument): Promise<void> => {
        const order: any = 'xxx by doc.extra.orderId';
        order.status = 'paid';
        await order.save()
      },
      alipayClient: new Client({
        appId: 'xxx',
        rsaPrivate: 'xxx',
        rsaPublic: 'xxx',
        signType: EClientSignType.RSA2,
        sandbox: true
      }),
      https: false
    },
  ],
};
 
export const production: IConfig = {
  roles: ['payments'],
  payments: [
    {
      path: 'order',
      channels: [EChannel.alipay],
      currencies: [ECurrency.cny],
      charge: async (ctx: IContext): Promise<IChargeDocument> => {
        const order: any = 'xxx';
        return {
          channel: ctx.request.fields.channel,
          currency: ECurrency.cny,
          client_ip: ctx.request.ip,
          subject: order.subject,
          body: order.body,
          amount: order.price,
          extra: {
            orderId: order._id,
          },
          __auth: ctx.request.auth._id,
        };
      },
      webhook: async (doc: IChargeDocument): Promise<void> => {
        const order: any = 'xxx by doc.extra.orderId';
        order.status = 'paid';
        await order.save()
      },
      alipayClient: new Client({
        appId: 'xxx',
        rsaPrivate: 'xxx',
        rsaPublic: 'xxx',
        signType: EClientSignType.RSA2,
        sandbox: true
      }),
      https: false
    },
  ],
};
 

Readme

Keywords

none

Package Sidebar

Install

npm i ycs-plugin-payments

Weekly Downloads

0

Version

0.5.12

License

MIT

Unpacked Size

69 kB

Total Files

20

Last publish

Collaborators

  • kuyoonjo