1.1.4 • Published 8 years ago

nativescript-fortumo-sms v1.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

npm npm

NativeScript fortumo SMS

A NativeScript module providing access to Fortumo SMS Gateway.

Donate

License

MIT license

Platforms

  • Android

Installation

Run

tns plugin add nativescript-fortumo-sms

inside your app project to install the module.

Android

AndroidManifest.xml

Keep sure to define the following permissions, activities and other data in your manifest file:

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Open Stores -->
    <uses-permission android:name="org.onepf.openiab.permission.BILLING" />
    <!-- Google -->
    <uses-permission android:name="com.android.vending.BILLING" />
    <!-- Nokia -->
    <uses-permission android:name="com.nokia.payment.BILLING" />
    <!-- Samsung -->
    <uses-permission android:name="com.sec.android.iap.permission.BILLING" />
    <!-- Fortumo -->
    <uses-feature android:name="android.hardware.telephony"
                  android:required="false" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <!-- SlideME -->
    <uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" />
    <!-- Skubit -->
    <uses-permission android:name="com.skubit.BILLING" />

    <application>
        <!-- Amazon -->
        <receiver android:name="com.amazon.device.iap.ResponseReceiver">
            <intent-filter>
                <action android:name="com.amazon.inapp.purchasing.NOTIFY"
                        android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
            </intent-filter>
        </receiver>
        <!-- Amazon -->

        <!-- Fortumo -->
        <receiver android:name="mp.MpSMSReceiver">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

        <service android:name="mp.MpService" />
        <service android:name="mp.StatusUpdateService" />

        <activity android:name="mp.MpActivity"
                  android:configChanges="orientation|keyboardHidden|screenSize"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <!-- Fortumo -->
    </application>
    
</manifest>

Demo

For quick start have a look at the demo/app/main-view-model.js file of the demo app to learn how it works.

Otherwise ...

Usage

Include

Include the module in your code-behind:

var FortumoSMS = require('nativescript-fortumo-sms');

Initialize

Initialize the environment:

function onPageLoaded(args) {
    FortumoSMS.init();
}
exports.onPageLoaded = onPageLoaded;

The (optional) object that is submitted to the PayPal.init function has the following structure:

Properties

NameDescription
onActivityResultOPTIONAL Logic for Activity.onActivityResult method of the underlying Android activity that is used to invoke logic for other modules, e.g.
requestCodeOPTIONAL The custom request code to use (e.g. for Activity.onActivityResult Android method). Default: 198612227

Start purchase

function buyProduct(args) {
    // configure
    var purchase = FortumoSMS.newPurchase()
        .setId('<PRODUCT-ID>')
        .setName('test product')
        .setSecret('<APP-SECRET>')
        .setDisplayName('A test product')
        .setAmount('1.95')
        .setCurrency('USD');

    // start purchase
    purchase.start(function(cbResult) {
        switch (cbResult.code) {
            case 0:
                // SUCCESS
                break;
                
            case 1:
                // CANCELLED
                break;
                
            case 2:
                // FAILED
                break;
                
            case 3:
                // PENDING
                break;
                
            case -1:
                // "unhandled exception"
                break;
        }
    });
}
exports.buyProduct = buyProduct;

The purchase object that is created by FortumoSMS.newPurchase function has the following structure.

Methods

NameDescription
isConsumableGets if the product is consumable or not. Example: var c = purchase.isConsumable();
getAmountGets the price. Example: var a = purchase.getAmount();
getCreditsMultiplierGets the multiplier for the credits. Example: var m = purchase.getCreditsMultiplier();
getCurrencyGets the currency. Example: var c = purchase.getCurrency();
getIdGets the product ID. Example: var id = purchase.getId();
getNameGets the product name. Example: var n = purchase.getName();
getSecretGets the app secret. Example: var s = purchase.getSecret();
setAmountSets the price. Example: payment.setAmount('1.25');
setCreditsMultiplierSets the multiplier for the credits. Example: purchase.setCreditsMultiplier(1.23);
setCurrencySets the currency. Example: purchase.setCurrency('USD');
setIdSets the product ID. Example: purchase.setId('<PRODUCT-ID>');
setIfConsumableSets if the product is consumable or not. Example: purchase.setIfConsumable(true);
setNameSets the product name. Example: purchase.setName('My product');
setSecretSets the app secret. Example: purchase.setSecret('<APP-SECRET>');
startStarts the purchase process.
start

The callback that is submitted to the purchase.start method receives an object with the following properties:

NameDescription
billing.statusThe billing status (if code = 0)
codeThe result code. 0 = success, -1 = unhandled exception, 1 = canceled, 2 = failed, 3 = pending
credit.amountThe credit amount (if code = 0)
credit.currencyThe credit name (if code = 0)
message.idThe message ID (if code = 0)
payment.codeThe payment code (if code = 0)
price.amountThe price amount (if code = 0)
price.currencyThe price currency (if code = 0)
product.nameThe product name (if code = 0)
service.idThe service ID (if code = 0)
skuSku (if code = 0)
user.idThe user ID (if code = 0)

Enhancements

Logging

If you want to get the logging output of the module, you can use FortumoSMS.addLogger function to add a callback that receives a message from the module:

FortumoSMS.addLogger(function(msg) {
    console.log('[nativescript-fortumo-sms]: ' + msg);
});
1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago