All files / src/models payment.js

62.5% Statements 5/8
0% Branches 0/2
50% Functions 3/6
62.5% Lines 5/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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121                                    14x   14x                                                                                                                 14x               2x               2x                                                      
import Model from 'model';
 
/**
 * The `Payment` model
 */
export default class Payment extends Model {
  static STATUS_OPEN = 'open';
  static STATUS_PENDING = 'pending';
  static STATUS_CANCELED = 'canceled';
  static STATUS_EXPIRED = 'expired';
  static STATUS_PAID = 'paid';
  static STATUS_FAILED = 'failed';
 
  static SEQUENCETYPE_ONEOFF = 'oneoff';
  static SEQUENCETYPE_FIRST = 'first';
  static SEQUENCETYPE_RECURRING = 'recurring';
 
  constructor(props) {
    super(props);
 
    const defaults = {
      resource: 'payment',
      id: null,
      mode: null,
      createdAt: null,
      status: null,
      isCancelable: null,
      paidAt: null,
      canceledAt: null,
      expiresAt: null,
      expiredAt: null,
      failedAt: null,
      amount: {
        value: null,
        currency: null,
      },
      amountRefunded: {
        value: null,
        currency: null,
      },
      amountRemaining: {
        value: null,
        currency: null,
      },
      description: null,
      redirectUrl: null,
      webhookUrl: null,
      method: null,
      metadata: null,
      locale: null,
      countryCode: null,
      profileId: null,
      settlementAmount: null,
      settlementId: null,
      customerId: null,
      sequenceType: null,
      mandateId: null,
      subscriptionId: null,
      applicationFee: {
        amount: {
          value: null,
          currency: null,
        },
        description: null,
      },
      details: null,
      _links: {
        checkout: null,
        refunds: null,
        chargebacks: null,
        settlement: null,
        mandate: null,
        subscription: null,
        customer: null,
      },
    };
 
    Object.assign(this, defaults, props);
  }
 
  /**
   * If the payment is open
   * @returns {boolean}
   */
  isOpen() {
    return this.status === Payment.STATUS_OPEN;
  }
 
  /**
   * If the payment is paid
   * @returns {boolean}
   */
  isPaid() {
    return !!this.paidAt;
  }
 
  /**
   * If the payment is canceled
   * @returns {boolean}
   */
  isCanceled() {
    return !!this.canceledAt;
  }
 
  /**
   * If the payment is expired
   * @returns {boolean}
   */
  isExpired() {
    return !!this.expiredAt;
  }
 
  /**
   * Get the payment URL
   * @returns {links|{paymentUrl, webhookUrl, redirectUrl}|Array|HTMLCollection|*|null}
   */
  getPaymentUrl() {
    return this.links && this.links.paymentUrl;
  }
}