0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Adds in-app purchase support to ProMotion.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

ProMotion-iap

Gem Version Build Status

ProMotion-iap is in-app purchase notification support for the popular RubyMotion gem ProMotion. It also works as a stand-alone gem if you are not using ProMotion.

Read the introductory blog post here: http://jamonholmgren.com/iap/

ProMotion-iap was created by Infinite Red, a web and mobile development company based in Portland, OR and San Francisco, CA. While you're welcome to use it, please note that we rely on the community to maintain it. We are happy to merge pull requests and release new versions but are no longer driving primary development.

Installation

gem 'ProMotion-iap'

Usage

PM::IAP::Product Class

The Product class is an abstraction layer that provides a simpler interface when working with a single IAP product. If you are dealing with multiple products you will want to use the IAP Module directly (documented below).

class PurchaseScreen < PM::Screen

  def on_load

    product = PM::IAP::Product.new("productid")

    product.retrieve do |product, error|
      # product looks something like the following
      {
        product_id:               "productid1",
        title:                    "title",
        description:              "description",
        price:                    <BigDecimal 0.99>,
        formatted_price:          "$0.99",
        price_locale:             <NSLocale>,
        downloadable:             false,
        download_content_lengths: <?>, # TODO: ?
        download_content_version: <?>, # TODO: ?
        product:                  <SKProduct>
      }
    end

    product.purchase do |status, data|
      case status
      when :in_progress
        # Usually do nothing, maybe a spinner
      when :deferred
        # Waiting on a prompt to the user
      when :purchased
        # Notify the user, update any affected UI elements
      when :canceled
        # They just canceled, no big deal.
      when :error
        # Failed to purchase
        data[:error].localizedDescription # => error message
      end
    end

    product.restore do |status, data|
      if status == :restored
        # Update your UI, notify the user
        # data is a hash with :product_id, :error, and :transaction
      else
        # Tell the user it failed to restore
      end
    end

  end
end

Product.new(product_id)

Stores the product_id for use in the instance methods.

retrieve(&callback)

Retrieves the product.

purchase(&callback)

Begins a purchase of the product.

restore(&callback)

Begins a restoration of the previously purchased product.

IAP Module

Include PM::IAP to add some in-app purchase methods to a screen, app delegate, or other class.

# app/screens/purchase_screen.rb
class PurchaseScreen < PM::Screen
  include PM::IAP

  def on_load

    retrieve_iaps [ "productid1", "productid2" ] do |products, error|
      # products looks something like the following
      [{
        product_id:               "productid1",
        title:                    "title",
        description:              "description",
        price:                    <BigDecimal 0.99>,
        formatted_price:          "$0.99",
        price_locale:             <NSLocale>,
        downloadable:             false,
        download_content_lengths: <?>, # TODO: ?
        download_content_version: <?>, # TODO: ?
        product:                  <SKProduct>
      }, {...}]
    end

    purchase_iaps [ "productid" ], username: User.current.username do |status, transaction|
      case status
      when :in_progress
        # Usually do nothing, maybe a spinner
      when :deferred
        # Waiting on a prompt to the user
      when :purchased
        # Notify the user, update any affected UI elements
      when :canceled
        # They just canceled, no big deal.
      when :error
        # Failed to purchase
        transaction.error.localizedDescription # => error message
      end
    end

    restore_iaps [ "productid" ], username: User.current.username do |status, data|
      if status == :restored
        # Update your UI, notify the user
        # This is called once for each product you're trying to restore.
        data[:product_id] # => "productid"
      elsif status == :error
        # Update your UI to show that there was an error.
        # This will only be called once, no matter how many products you are trying to restore.
        # You'll get an NSError in your `data` hash.
        data[:error].localizedDescription # => description of error
      end
    end


  end
end

retrieve_iaps(*product_ids, &callback)

Retrieves in-app purchase products in an array of mapped hashes. The callback method should accept products and error.

purchase_iaps(*product_ids, &callback)

Prompts the user to login to their Apple ID and complete the purchase. The callback method should accept status and transaction. The callback method will be called several times with the various statuses in the process. If more than one product_id is provided the callback method will be called several times per product with the applicable transaction.

restore_iaps(*product_ids, &callback)

Restores a previously purchased IAP to the user (for example if they have upgraded their device). This relies on the Apple ID the user enters at the prompt. Unfortunately, if there is no purchase to restore for the signed-in account, no error message is generated and will fail silently.

Important Note

In order for this library to work correctly, you must provide your, app.identifier to the Rakefile.

Find the Product ID here:

product id

Authors

| Contributor | Twitter | | Jamon Holmgren | @jamonholmgren | | Kevin VanGelder | @kevinvangelder |

Inspired By

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Make some specs pass
  5. Push to the branch (git iap origin my-new-feature)
  6. Create new Pull Request