bdhobare / mpesa-android-sdk

An android SDK for MPESA.
44 stars 52 forks source link

Invalid Access Token #5

Closed benimachira closed 4 years ago

benimachira commented 6 years ago

When i click pay i get Invalid Access Token. My Access token in Daraja Dashboard is active and have not yet expired.

I am using the test details from the dashboard as below public static final String BUSINESS_SHORT_CODE = "174379"; public static final String PASSKEY = "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919";

`private void pay(String phone, int amount){ dialog.show();

    STKPush.Builder builder = new STKPush.Builder(BUSINESS_SHORT_CODE, PASSKEY, amount,BUSINESS_SHORT_CODE, phone);

// SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); // String token = sharedPreferences.getString("InstanceID", "");

    builder.setFirebaseRegID(FIREBASE_KEY);
    builder.setCallBackURL(CALLBACK_URL);
    STKPush push = builder.build();

    Mpesa.getInstance().pay(this, push);

}`

the OnError method is the one that returns that message.

@Override public void onMpesaError(Pair<Integer, String> result) { Toast.makeText(context,"Auth error: "+result.message,Toast.LENGTH_LONG).show(); dialog.dismiss(); }

What would be causing this Since i am on the sandbox. And in the code there is no option of inputting the access key generated from daraja dashboard { "access_token": "", "expires_in": "3599" }

bdhobare commented 6 years ago

If you are in the sandbox make sure to to initialize like Mpesa.with(context, CONSUMER_KEY, CONSUMER_SECRET, Mode.SANDBOX);

benimachira commented 6 years ago

That i have , have you tried to use the app(with test credentials ) it is like there is an issue with the test credentials provided by safaricom. Since the error is still the same, since that methods is being executed and success is ok. ` @Override public void onAuthSuccess() { Toast.makeText(context,"Auth succes ",Toast.LENGTH_LONG).show();

    pay.setEnabled(true);

}`
bdhobare commented 6 years ago

Ok. Let me look at it. It must have been a recent change then since I have always keep a tabs with the documentation.

remymumoh commented 5 years ago

A tip for the next guy, just incase you get this error, when you creating the app on daraja dashboard, ensure that Lipa na Mpesa is selected when creating the app