RecurlySubscription.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { ObjectId } = require('../../../../app/src/infrastructure/mongojs')
  2. const Subscription = require('./Subscription')
  3. const MockRecurlyApi = require('./MockRecurlyApi')
  4. const RecurlyWrapper = require('../../../../app/src/Features/Subscription/RecurlyWrapper')
  5. class RecurlySubscription {
  6. constructor(options = {}) {
  7. this.subscription = new Subscription(options)
  8. this.uuid = ObjectId().toString()
  9. this.accountId = this.subscription.admin_id.toString()
  10. this.state = options.state || 'active'
  11. }
  12. ensureExists(callback) {
  13. this.subscription.ensureExists(error => {
  14. if (error) {
  15. return callback(error)
  16. }
  17. MockRecurlyApi.addSubscription({
  18. uuid: this.uuid,
  19. account_id: this.accountId,
  20. state: this.state
  21. })
  22. MockRecurlyApi.addAccount({ id: this.accountId })
  23. callback()
  24. })
  25. }
  26. buildCallbackXml() {
  27. return RecurlyWrapper._buildXml('expired_subscription_notification', {
  28. subscription: {
  29. uuid: this.uuid
  30. }
  31. })
  32. }
  33. }
  34. module.exports = RecurlySubscription