Subscription API - Commit draft without payment information.

fabcam
Tourist
4 0 1

Hi all,
What I need to accomplish is to create a subscription without payment information associated to it. I tried to do it with the API, creating a subscription draft, adding lines to it and the committing it. But I got the error that payment information was missing. 

The scenario is as follows: I'm using subscriptions to create memberships, and sometimes we need to grant free membership to some users. Is this the way to go? Maybe there is some other thing to do that I'm not seeing.

Thanks in advance!!

Replies 5 (5)

Luke_K
Shopify Staff
402 66 100

Hey @fabcam

Would you mind sharing the API call you made? I can take a look into it. Considering your use case, the subscriptionDraftDiscountAdd mutation could help you out.

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
fabcam
Tourist
4 0 1

Hi @Luke_K, I'm going to try adding a discount as you said and let you know, however the variant I'm using while adding a line to the subscription draft has a $0 cost.
Thanks!

fabcam
Tourist
4 0 1

Hi again @Luke_K , sorry for the late reply. You know I tried adding a discount but it wasn't enough for stopping the error message asking me for payment information.

I'm going to paste here the mutations that I'm running in case you want to have a look.

 

Create Subscription Contract Draft:

mutation {
      subscriptionContractCreate(
        input: {
          customerId: "<customer gid>"
          nextBillingDate: "2021-08-01"
          currencyCode: USD
          contract: {
            status: ACTIVE
            billingPolicy: { interval: MONTH, intervalCount: 1 }
            deliveryPolicy: { interval: MONTH, intervalCount: 1 }
            deliveryPrice: 0.0
          }
        }
      ) {
        draft {
          id
        }
        userErrors {
          field
          message
        }
      }
    }

 

Add Product Line to Subscription Draft:

mutation {
        subscriptionDraftLineAdd(
          draftId: "<subscription draft gid>"
          input: {
            productVariantId: "<product variant gid>"
            quantity:1
            currentPrice:0.0
          }
        ) {
          lineAdded {
            id
            quantity
            productId
            variantId
          }
          draft {
            id
          }
          userErrors {
            ...
          }
        }
      }

 

Add discount to Subscription Draft:

mutation {
      subscriptionDraftDiscountAdd(
        draftId: "<subscription draft gid>"
        input: {
          title: "Freee Subscription"
          value: {
            percentage: 100
          }
          entitledLines: {
            all: true
          }
        })
        {
          discountAdded {
            id
            rejectionReason
          }
          draft {
            id
          }
          userErrors {
            ...
          }
        }
    }

 

And at the end the commit subscription draft:

mutation {
      subscriptionDraftCommit(draftId: "<subscription draft gid>") {
        contract {
          id
        }
        userErrors {
          field
          message
        }
      }
    }

 

Thanks!!

Luke_K
Shopify Staff
402 66 100

Hey @fabcam 

Diffing your SubscriptionContractCreate mutation against the one prescribed in our documentation here, it appears you are omitting a paymentMethodId from the call. 

I think additionally this will be a point where you get stuck when it comes to the final subscriptionDraftCommit unfortunately as the API is expecting a CustomerPaymentMethod Id and validates the commit against it. Considering this, perhaps setting the Customer Payment Id earlier on could be a step in the right direction. 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
fabcam
Tourist
4 0 1

Ok @Luke_K, yes, that's what I wanted to avoid! thank you very much!