Skip to main content
Samsung Developer Program

Initialize Samsung IAP

 

Modify your Android app's MainActivity class to support the sale of in-app items registered to your Android app.

 

Initialize the MainActivity Class

You support Samsung IAP operation by including the following:

  • Implement IAP listeners to receive information in callback events for IAP method call processing.
    For more details, see IAP Helper Callback Listeners.
  • You can either hard-code in-app item IDs or get them with getProductDetails().
  • You must instantiate IAP Helper in order to use Samsung IAP functionality.
    For more details, see getInstance().
  • You must set the operating mode to the appropriate test more or normal mode.
    See the next section.
     

The example code in this section demonstrates how to implement a listener, hard-code an in-app item ID, instantiate an IapHelper object, and set the IAP operating mode. 

public class MainActivity extends AppCompatActivity implements OnPaymentListener {
    // Please change ITEM_ID for your application's in-app items.     
    // ========================================================================     
    private static final String ITEM_ID  = "Nuclear";     
    // ========================================================================

    private IapHelper    mIapHelper  = null;

    @Override     
    protected void onCreate(Bundle savedInstanceState) {         
        super.onCreate(savedInstanceState);         
        setContentView(R.layout.activity_main);
        
        mIapHelper = IapHelper.getInstance(this);         
        mIapHelper.setOperationMode(OPERATION_MODE_PRODUCTION);     
    }
    public void doPurchase(View _view) {         
        // The passThroughParam should be a generated value by you.         
        mIapHelper.startPayment(ITEM_ID, "pLKjLKjLJL87=76df56rf+4f5", true, this);
    } 
 
    @Override    
    public void onPayment(ErrorVo _errorVO, PurchaseVo _purchaseVO) { 
 
        // Success or failure of payment is processed here.     
    } 
}

Set the IAP Operating Mode

In order to test Samsung IAP before normal production mode release, set the IAP operating mode to either of the two developer test modes. After you have completed development and testing and before you submit your Android app and its in-app items for validation, set the operating mode to the default normal production release mode.

Caution: Setting production mode before validation submission blocks all IAP method requests. Setting either test mode and submitting your app to validation testing blocks all purchase and payment transactions when your app is distributed in the Galaxy Apps store.

Use setOperationMode() to set the IAP operating mode:

  • IAP_MODE_PRODUCTION: Default Normal production release mode where all IAP method calls are processed as specified, and successful and failure results can be returned.

    Caution: Successful purchase and payment transactions do result in financial billing (for example, credit card payment) of the end user.

  • IAP_MODE_TEST: Developer test mode where all IAP method calls are processed as specified, and successful results are always returned.

    Note: Purchase and payment transaction do not result in financial billing of the end user.

  • IAP_MODE_TEST_FAILURE: Developer test mode where all IAP method calls are not processed, and failure results are always returned.

    Note: Purchase and payment transaction do not result in financial billing of the end user.
     

For example:

samsung::IAP::setOperationMode(IAP_MODE_TEST);

 

For more details, see setOperationMode().

 

  • Was this article helpful?