Coder Social home page Coder Social logo

extension-iap-nme's Introduction

MIT License Haxelib Version Build Status

ATTENTION

This extension needs your love and commits. If you are using it, please consider sending your fixes so it will stay up-to-date. I will happily merge your requests, tag me for faster processing. :) Thank you.

IAP

Provides an access to in-app purchases (iOS) and in-app billing (Android) for OpenFL projects using a common API.

Installation

You can easily install IAP using haxelib:

haxelib install extension-iap

To add it to a Lime or OpenFL project, add this to your project file:

<haxelib name="extension-iap" />

Usage

1. Initialize iap:

// required only for Google Play
var publicKey:String = "";

#if android
publicKey = "ANDROID_PUBLIC_KEY";
#elseif ios
publicKey = "";
#end

function onPurchaseInitSuccess(e:IAPEvent) {
    // OK
}

function onPurchaseInitFailed(e:IAPEvent) {
    // reason: e.message
}

IAP.addEventListener(IAPEvent.PURCHASE_INIT, onPurchaseInitSuccess);
IAP.addEventListener(IAPEvent.PURCHASE_INIT_FAILED, onPurchaseInitFailed);

IAP.manualTransactionMode = true;
IAP.initialize(publicKey);

2. Receive shop items data:

function onProductsDataComplete(e:IAPEvent) {
    // e.productsData is array of ProductDetails
    for (data in e.productsData) {
        // data.productId, data.price, data.localizedPrice, ...
    }
}

function onProductsDataFailed(e:IAPEvent) {
    // reason: e.message
}

IAP.addEventListener(IAPEvent.PURCHASE_PRODUCT_DATA_COMPLETE, onProductsDataComplete);
IAP.addEventListener(IAPEvent.PURCHASE_PRODUCT_DATA_FAILED, onProductsDataFailed);

var productIds:Array<String> = ["item_id_1", "item_id_2", ...];
IAP.requestProductData(productIds);

3. Perform purchase:

function onPurchaseSuccess(e:IAPEvent):Void {
    // purchase was completed
    // productID: e.productID
    // e.purchase - pass it for consuming
    // or you can get it from inventory after purchasing: IAP.inventory.getPurchase(productID)
}

function onPurchaseFail(e:IAPEvent):Void {
    // purchase was failed, reason: e.message
}

function onPurchaseCancel(e:IAPEvent):Void {
    // purchase was cancelled by user
}

IAP.addEventListener(IAPEvent.PURCHASE_SUCCESS, onPurchaseSuccess);
IAP.addEventListener(IAPEvent.PURCHASE_FAILURE, onPurchaseFail);
IAP.addEventListener(IAPEvent.PURCHASE_CANCEL, onPurchaseCancel);

IAP.purchase(productId);

4. Consume purchase:

function onConsumeSuccess(e:IAPEvent):Void {
    // purchase was consumed and not in IAP.inventory anymore
}

function onConsumeFail(e:IAPEvent):Void {
    // reason: e.message
}

IAP.addEventListener(IAPEvent.PURCHASE_CONSUME_SUCCESS, onConsumeSuccess);
IAP.addEventListener(IAPEvent.PURCHASE_CONSUME_FAILURE, onConsumeFail);

IAP.consume(purchaseData);

Development Builds

Clone the IAP repository:

git clone https://github.com/openfl/extension-iap

Tell haxelib where your development copy of IAP is installed:

haxelib dev extension-iap extension-iap

You can build the binaries using "lime rebuild"

lime rebuild extension-iap ios

To return to release builds:

haxelib dev extension-iap

extension-iap-nme's People

Contributors

slabgames avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.