Fortumo Nook SDK – ShiVa Engine

Fortumo Nook SDK

Nav Gupta: “NOOK in-app payments use the Fortumo SDK that top Android developers are already using for making money elsewhere. With one development effort and easy integration, you can monetize users on NOOK tablets and other Android devices and marketplaces around the world.”

Fortumo Account Setup

– 1. Create an account on Fortumo.com
– 2. Log in and click on My Services
– 3. Click on Create New Service for Nook (fortumo.com/nook)
– 4. When the page loads, fill in the name of your App. This must be all in one word format (meaning no spaces).
This will be the name that is shown to the user when they read their credit card statement. To keep it simple, I keep the name of the app, but this can be whatever you believe is best for your end users.
– 5. Enter the name of the virtual item, like com.companyname.appname.iap_item_name
– 6. Enter a price for your item. In Fortumo, the lowest price in USD is $1.99.
– 7. If your IAP is related to Adult/Erotic, Lotteries/Gambling or Donations, chances are it’s not allowed on Nook and will be a cause for rejection
– 8. Ignore the URL step, because this only applies if you have your own server set up for purchases.
– 9. Enter your customer support info.
– 10. Review the terms of service and hit Confirm.
– 11. Repeat from step 3 and add all the services you need

SDK Download and Setup

I’m assuming at this point you’ve already setup and got MASS for Android working and running so this will continue after you’ve already got that setup.
– 1. Download the Fortumo In-App Purchasing Library by clicking on any of your services,
– then at the top bar, click on Setup, and you should now see the “Downlod Fortumo In-App Purchasing Library” link.
– 2. Import and set up the Jar file in your Eclipse project. Create a new project for this.
– 3. Configure the SDK like so: developers.fortumo.com/in-app-pu … g-the-sdk/.
Make sure you set up your Manifest file correctly!
Make sure your payment receiver code looks like this:

       
           
              
           
       

– 4. At the top of our main Java file (YourAppName.java) add the following imports:

// Fortumo Code
import com.fortumo.android.Fortumo;
import com.fortumo.android.PaymentActivity;
import com.fortumo.android.PaymentRequest;
import com.fortumo.android.PaymentRequestBuilder;
import com.fortumo.android.PaymentResponse;
import android.content.BroadcastReceiver;

– 5. We do not need to extend the Activity of our main class. Instead we do the following before the onCreate (approx. line 180):

   // FORTUMO SPECIFIC Functions
    private static final int REQUEST_CODE = 1234; // Can be anything
    protected final void makePayment(PaymentRequest payment) {
        startActivityForResult(payment.toIntent(this), REQUEST_CODE);
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE) {
            if(data == null) {
                return;
            }
            // OK
            if (resultCode == RESULT_OK) {
                PaymentResponse response = new PaymentResponse(data);
                switch (response.getBillingStatus()) {
                    case Fortumo.MESSAGE_STATUS_BILLED:
                    // ...
                    break;
                case Fortumo.MESSAGE_STATUS_FAILED:
                    // ...
                    break;
                case Fortumo.MESSAGE_STATUS_PENDING:
                    // ...
                    break;
                }
            // Cancel
            } else {
                // ..
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
   // END OF FORTUMO SPECIFIC Functions

– 6. In the onCreate function of our main class, add the following code near the bottom of the function:

      // set the permission which protects the payment related broadcasts by
      // Fortumo
      Fortumo.enablePaymentBroadcast(this, Manifest.permission.PAYMENT_INFO_BROADCAST_PERMISSION);

– 7. Now wherever we want to call the purchase link, we will write the following fortumo code:

        PaymentRequestBuilder builder = new PaymentRequestBuilder();
        builder.setService("YOUR_SERVICE_ID_HERE","YOUR_IN_APP_SECRET_HERE");
        builder.setProductName("YOUR_PRODUCT_NAME_HERE"); // Product Name on Fortumo Website
        builder.setDisplayString("1000 Gears"); // Name of Product
        builder.setIcon(R.drawable.app_icon);
        builder.setConsumable(true); // Product is a consumable product or not
        oThis.makePayment(builder.build());

Make sure to edit your service ID, app secret and enter your product name as it appears on the Fortumo site. I usually keep my product names in capital letters with underscores.
Example: ITEM_5000_GEARS
– 8. Create the purchase code for each product you wish to sell in it’s own section
– 9. Now we need to save the file and create a new class that is separate. Right click on your package name, like com.yourcompany.yourapp, then click on New->Class.
– Name the class “PaymentStatusReceiver” (without the quotes).
– 10. Copy and paste the following code into the file and replace the top package name with your own package name as well as the intent (in the middle of the code):

package com.gamescorpion.dungeonwagon;
// FORTUMO PaymentStatusReceiver
import com.fortumo.android.Fortumo;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class PaymentStatusReceiver extends BroadcastReceiver  {
    public void onReceive(Context context, Intent intent) {
      Bundle extras = intent.getExtras();
      int billingStatus = extras.getInt("billing_status");
      if (billingStatus == Fortumo.MESSAGE_STATUS_BILLED) {
         String serviceId = extras.getString("service_id");
         String productName = extras.getString("product_name");
         // Define all your products here using this as a template
         /*
         if (serviceId.equals("YOUR_SERVICE_ID_HERE") && productName.equals("YOUR_PRODUCT_NAME_HERE"))
         {
            // Take Action (Create a ShiVa Reverse Hook/Callback here to take action on a successful purchase)
         }
         */
         // the changes to the user data are made, inform anyone who is
         // interested
         Intent dataUpdated = new Intent("com.gamescorpion.dungeonwagon.intents.DATA_UPDATED");
         context.sendBroadcast(dataUpdated);
      }
      else
      {
         // Transaction failed, Do failed code below
         // Take Action (Create a ShiVa Reverse Hook/Callback here to take action on a failed purchase)
      }
   }
}

11. Save and compile your code and you should (if you put the fortumo call inside a button) be able to see the Fortumo IAP window pop up and function correctly.
12. Create a test account, so you can use the fake credit cards they provide for devs to test out fake transactions here: developers.fortumo.com/in-app-pu … k/testing/

Further Reading

Fortumo Documentation – developers.fortumo.com




Need more answers?

  • slackBanner