Scrip v1.0.0 Scrip View Source

Scrip is a library to verify Apple App Store receipts. See the Apple docs for more information

Installation

The package can be installed by adding scrip to your list of dependencies in mix.exs:

def deps do
  [
    {:script, "~> 1.0.0"},
    {:jason, "~> 1.1"}, # optional
    {:httpoison, "~> 1.7"}, # optional
  ]
end

Jason and HTTPoison are optional and can be overriden with other implementations but these are the default implementations. See Scrip.Config for more information.

Usage

First set up In-App Purchases in App Store Connect. For your app should set the App-Specific Shared Secret, we can use this later on to verify the receipt.

The usual flow is that your app does an in app purchase. This returns a Base64 receipt to the app. Your app can send the receipt data to your backend to validate against the Apple servers.

The backend can verify the validity of this receipt using Scrip.verify_receipt("BASE64_RECEIPT_DATA", password: "*App-Specific Shared Secret*"). It needs the earlier create App-Specific Shared Secret.

If all goes well, it returns an :ok tuple with the IAP information you can store on your backend. Otherwise an :error tuple is returned.

See Scrip.verify_receipt/3 for more information

Link to this section Summary

Types

The Base64 encoded receipt data.

UNIX epoch time format, in milliseconds.

Functions

Call verify_receipt/3 with the Base64 receipt and a valid password to verify the App Store receipts.

Link to this section Types

Specs

receipt_data() :: String.t()

The Base64 encoded receipt data.

Specs

timestamp() :: integer()

UNIX epoch time format, in milliseconds.

Link to this section Functions

Link to this function

verify_receipt(receipt_data, mode \\ :production, opts \\ [])

View Source

Specs

Call verify_receipt/3 with the Base64 receipt and a valid password to verify the App Store receipts.

Examples

> Scrip.verify_receipt("BASE64_DATA", password: "secret")
{:ok, %Scrip.Response{status: 0}}

You can explicitly specify the environment. It defaults to :production, and will retry on the :sandbox environment. See Apple docs

> Scrip.verify_receipt("BASE64_DATA", :sandbox, password: "secret")

Returns an error tuple when something went wrong:

> Scrip.verify_receipt("BASE64_DATA", password: "wrong password")
{:error, %Scrip.Response{}}