Class: ShopifyGraphql::CreateRecurringSubscription
- Inherits:
-
Object
- Object
- ShopifyGraphql::CreateRecurringSubscription
- Includes:
- Mutation
- Defined in:
- app/graphql/shopify_graphql/create_recurring_subscription.rb
Constant Summary collapse
- MUTATION =
"\#{AppSubscriptionFields::FRAGMENT}\n\nmutation appSubscriptionCreate(\n $name: String!,\n $lineItems: [AppSubscriptionLineItemInput!]!,\n $returnUrl: URL!,\n $trialDays: Int,\n $test: Boolean\n) {\n appSubscriptionCreate(\n name: $name,\n lineItems: $lineItems,\n returnUrl: $returnUrl,\n trialDays: $trialDays,\n test: $test\n ) {\n appSubscription {\n ... AppSubscriptionFields\n }\n confirmationUrl\n userErrors {\n field\n message\n }\n }\n}\n"
Instance Method Summary collapse
Methods included from Mutation
Instance Method Details
#call(name:, price:, return_url:, trial_days: nil, test: nil, interval: :monthly) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/graphql/shopify_graphql/create_recurring_subscription.rb', line 34 def call(name:, price:, return_url:, trial_days: nil, test: nil, interval: :monthly) payload = {name: name, returnUrl: return_url} plan_interval = interval == :monthly ? "EVERY_30_DAYS" : "ANNUAL" payload[:lineItems] = [{ plan: { appRecurringPricingDetails: { price: {amount: price, currencyCode: "USD"}, interval: plan_interval } } }] payload[:trialDays] = trial_days if trial_days payload[:test] = test if test response = execute(MUTATION, **payload) response.data = response.data.appSubscriptionCreate handle_user_errors(response.data) response.data = parse_data(response.data) response end |