All files / src/entities payment.ts

78.12% Statements 25/32
0% Branches 0/3
33.33% Functions 1/3
79.31% Lines 23/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 661x 1x 1x 1x     1x 1x 1x 1x   1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x                           1x  
import { Entity } from '../entity.js';
import { Invoice } from './invoice.js';
import { User } from './user.js';
import { AutomaticPaymentRelationship } from './automatic_payment_relationship.js';
import { RequestOptions } from '../request.js';
 
export class Payment extends Entity {
  protected static resourceName = 'payments';
  protected static singularName = 'payment';
  protected static pluralName = 'payments';
 
  @Payment.property({ type: Date })
  public archived?: Date | null;
 
  @Payment.property()
  public id?: number;
 
  @Payment.property()
  public payDate?: Date;
 
  @Payment.property()
  public paymentType?: number;
 
  @Payment.property()
  public note?: string;
 
  @Payment.property()
  public amount?: number;
 
  @Payment.property()
  public autoRefundable?: boolean;
 
  @Payment.property({ type: Date })
  public refunded?: Date | null;
 
  @Payment.property()
  public sendSms?: boolean;
 
  @Payment.property()
  public sendEmail?: boolean;
 
  @Payment.property({ type: Invoice })
  public invoice?: Invoice | null;
 
  @Payment.property({ type: User })
  public paymentRecorder?: User | null;
 
  @Payment.property({ type: User })
  public refundIssuer?: User | null;
 
  @Payment.property({ type: AutomaticPaymentRelationship })
  public chargedByPaymentRelationship?: AutomaticPaymentRelationship | null;
 
  public refund = () => {
    const resource = `/payments/${this.id}/refund/`;
    const fetchOptions: RequestOptions = { method: 'POST' };
 
    return this.merchi
      .authenticatedFetch(resource, fetchOptions)
      .then((data: any) => {
        this.fromJson(data);
        return this;
      });
  };
}