Class: ShopifyOracle::Accessor::SubscriptionContract

Inherits:
Base
  • Object
show all
Defined in:
lib/shopify_oracle/accessor/subscription_contract.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#gid, #object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

class_name, find, list

Constructor Details

#initialize(id:) ⇒ SubscriptionContract

Returns a new instance of SubscriptionContract.



91
92
93
94
# File 'lib/shopify_oracle/accessor/subscription_contract.rb', line 91

def initialize(id:)
  super
  @contract = @object
end

Instance Attribute Details

#contractObject (readonly)

Returns the value of attribute contract.



89
90
91
# File 'lib/shopify_oracle/accessor/subscription_contract.rb', line 89

def contract
  @contract
end

Class Method Details

.create(customer:, interval: 'WEEK', intervalCount: 6, maxCycles: 10, minCycles: 3, deliveryPrice: 5.50, nextBillingDate: Time.zone.today + 30.days) ⇒ Object

rubocop:disable Metrics/MethodLength



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
# File 'lib/shopify_oracle/accessor/subscription_contract.rb', line 23

def create(
  customer:,
  interval: 'WEEK',
  intervalCount: 6,
  maxCycles: 10,
  minCycles: 3,
  deliveryPrice: 5.50,
  nextBillingDate: Time.zone.today + 30.days
)

  address = customer.default_address
  input = {
    contract: {
      billingPolicy: {
        interval:,
        intervalCount:,
        maxCycles:,
        minCycles:
      },
      customAttributes: [
        {
          key: 'key',
          value: 'value'
        }
      ],
      deliveryMethod: {
        shipping: {
          address: {
            address1: address.address1,
            address2: address.address2,
            city: address.city,
            company: address.company,
            firstName: address.first_name,
            lastName: address.last_name,
            phone: address.phone,
            provinceCode: address.region_code,
            zip: address.zip,
            countryCode: address.country_code
          },
          shippingOption: {
            code: 'abc',
            description: 'description',
            presentmentTitle: 'title',
            title: 'title'
          }
        }
      },
      deliveryPolicy: {
        interval:,
        intervalCount:
      },
      deliveryPrice:,
      nextBillingDate:,
      note: 'note',
      status: 'ACTIVE'
    },
    customerId: "gid://shopify/Customer/#{customer.ext_id}",
    nextBillingDate: Time.zone.today + 30.days,
    currencyCode: 'GBP'
  }

  ShopifyOracle.mutate(:create_subscription_contract, input:)
end

.create_v2(customer_id:, customerPaymentMethodId:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/shopify_oracle/accessor/subscription_contract.rb', line 9

def create_v2(
  customer_id:,
  customerPaymentMethodId:
)
  customerId = customer_id.is_a?(Integer) ? "gid://shopify/Customer/#{customer_id}" : customer_id

  ShopifyOracle.mutate(
    :create_subscription_contract_v2,
    customerId:,
    customerPaymentMethodId:
  )
end

Instance Method Details

#reloadObject



96
97
98
99
# File 'lib/shopify_oracle/accessor/subscription_contract.rb', line 96

def reload
  super
  @contract = @object
end