All files / src/models refund.js

87.5% Statements 7/8
100% Branches 0/0
83.33% Functions 5/6
87.5% Lines 7/8
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 66 67 68 69 70 71 72 73 74 75 76 77                          10x   10x                                   10x               2x               2x               2x               2x                      
import Model from 'model';
 
/**
 * The `Refund` model
 */
export default class Refund extends Model {
  static STATUS_QUEUED = 'queued';
  static STATUS_PENDING = 'pending';
  static STATUS_PROCESSING = 'processing';
  static STATUS_REFUNDED = 'refunded';
  static STATUS_FAILED = 'failed';
 
  constructor(props) {
    super(props);
 
    const defaults = {
      resource: 'refund',
      id: null,
      amount: {
        currency: null,
        value: null,
      },
      settlementAmount: null,
      description: null,
      status: null,
      createdAt: null,
      paymentId: null,
      _links: {
        payment: null,
        settlement: null,
      },
    };
 
    Object.assign(this, defaults, props);
  }
 
  /**
   * The refund is queued until there is enough balance to process te refund. You can still cancel the refund.
   * @returns {boolean}
   */
  isQueued() {
    return this.status === Refund.STATUS_QUEUED;
  }
  
  /**
   * The refund will be sent to the bank on the next business day. You can still cancel the refund.
   * @returns {boolean}
   */
  isPending() {
    return this.status === Refund.STATUS_PENDING;
  }
 
  /**
   * The refund has been sent to the bank. The refund amount will be transferred to the consumer account as soon as possible.
   * @returns {boolean}
   */
  isProcessing() {
    return this.status === Refund.STATUS_PROCESSING;
  }
 
  /**
   * The refund amount has been transferred to the consumer.
   * @returns {boolean}
   */
  isRefunded() {
    return this.status === Refund.STATUS_REFUNDED;
  }
 
  /**
   * The refund has failed during processing.
   * @returns {boolean}
   */
  isFailed() {
    return this.status === Refund.STATUS_FAILED;
  }
}