Skip to content

Instantly share code, notes, and snippets.

@v3ss0n
Created March 11, 2017 17:43
Show Gist options
  • Save v3ss0n/d8193717316843f07029ea8cbffcc068 to your computer and use it in GitHub Desktop.
Save v3ss0n/d8193717316843f07029ea8cbffcc068 to your computer and use it in GitHub Desktop.
package com.hexyn.hover;
import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
import android.widget.Toast;
import com.hover.sdk.main.HoverParameters;
import com.hover.sdk.onboarding.HoverIntegrationActivity;
import com.hover.sdk.operators.Permission;
import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import static android.app.Activity.RESULT_CANCELED;
/**
* Created by boggy on 3/10/17.
*/
public class BuyNow extends CordovaPlugin{
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
Intent integrationIntent = new Intent(cordova.getActivity(), HoverIntegrationActivity.class);
integrationIntent.putExtra(HoverIntegrationActivity.SERVICE_IDS, new int[] { 11 });
integrationIntent.putExtra(HoverIntegrationActivity.PERM_LEVEL, Permission.NORMAL);
cordova.getActivity().startActivityForResult(integrationIntent, 200);
// your init code here
}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if(action.equals("buy"))
{
Context con=cordova.getActivity().getApplicationContext();
try {
Toast.makeText(cordova.getActivity(),"Success",Toast.LENGTH_LONG).show();
Intent i = new HoverParameters.Builder(cordova.getActivity()).request("send",args.getString(1), "MMK", args.getString(0)).from(11).buildIntent();
cordova.getActivity().startActivityForResult(i, 0);
} catch (JSONException e){
callbackContext.error("Failed to parse parameters");
}
}
return true;
}
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
if (requestCode == 200 ) {
Toast.makeText(cordova.getActivity().getApplicationContext(), "Error: " + data.getStringExtra("error"), Toast.LENGTH_LONG).show();
} else if (requestCode == 200 ) {
Toast.makeText(cordova.getActivity().getApplicationContext(), "Success! ServiceId: " + data.getIntExtra("serviceId", -1) + ", Service Name: " + data.getStringExtra("serviceName") + ", Currency: " + data.getStringExtra("currency") + ", Country Name: " + data.getStringExtra("countryName") + ", Operator: " + data.getStringExtra("opSlug"), Toast.LENGTH_LONG).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment