Tutorial: Apple In-App Purchase

Prerequisites

Before iOS application and middleware can be connected to Apple In-App Purchase, following steps must be completed:

  1. Setting up App Store account and creating application - see tutorial.
  2. Adding test products - see tutorial.

    Important notes for setting up products compatible with Cleeng:

    • The product references have to be the same as Cleeng's offer IDs.
    • Product price must be set manually in iTunes Connect. Make sure to align prices between Apple's product and Cleeng offer.
      You can only select price tiers in the iTunes connect, make sure the video’s in the Cleeng database have the same price.
    • Use non-renewing-subscription products for subscriptions for a specific period of time. The subscriptions are removed from the receipt after the App has retrieved access to the product automatically. It means that application must rely on Cleeng when checking entitlement.
    • Use non-consumable for subscriptions that are forever. They will remain on the receipt forever.
    • To test, logout of iTunes Connect on you phone and login with on of the sandbox account created in the iTunes Connect -> Users and Roles -> Sandbox Testers (see tutorial).

Authentication is described in this section.

Purchase Flow

iOS Application is responsible for displaying a Pay Button that will initiate the payment (see Apple documentation). Once payment is completed, App Store will return a receipt object that needs to be passed through the middleware to Cleeng's Receipt Endpoint.

Pay Button Logic

After purchase is completed, application and middleware should enter polling mode. They should make a request to getAccessStatus API every 5 seconds until transaction is completed. If access is not granted within 60 seconds, application should assume it failed and inform user accordingly. If transaction is confirmed, video content can be revealed.

Polling getAccessStatus

Communication with Receipt Endpoint

Endpoints:

  • Production URL: https://cleeng.com/apple/payment
  • Sandbox URL: https://sandbox.cleeng.com/apple/payment

Request:

  1. Request method: POST
  2. Required headers:

    • Content-Type: application/json
    • X-Publisher-Token: publisher_token
    • Authorization: Basic auth_token - token provided by Cleeng
  3. Json payload example

    {
      customerEmail: "example@email.com",
      offerId: "S598742062_US",
      receipt: {
        transactionId: "1234565432",
        receiptData: receipt_data
      },
      appType: app_type,
      ipAddress: "192.168.1.1"
    }
    
  4. Parameters describe

    • customerEmail - email registered to customer account (eg. example@email.com)
    • offerId - identifier for Cleeng offer (eg E123123123_US)
    • transactionId - transaction identifier returned from iTunes store
    • receiptData - complete receipt data returned from iTunes store
    • appType - one of apple device ios or tvos
    • ipAddress - viewer ip address, optional parameter
  5. Example json response:

    {
      "message": "OK"
    }
    
  6. Response describe

    • message - processing result
  7. HTTP status codes

    • 400 - Invalid parameters
    • 401 - Invalid authentication // broadcaster and viewer
    • 422 - Unprocessable entity
    • 200 - OK
    • 500 - Internal Server Error

Receipt processing is an asynchronous process that may take up to 30 seconds, therefore application needs to poll Cleeng API (getAccessStatus method) until transaction is completed and access is granted.


We use cookies to ensure that we provide you the best service and website experience. Read our Cookie policy for more details.