Android Open Source - Java-Yandex.Money-API-SDK Yandex Money Droid






From Project

Back to project page Java-Yandex.Money-API-SDK.

License

The source code is released under:

MIT License

If you think the Android project Java-Yandex.Money-API-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ru.yandex.money.droid;
/* ww  w .  j  a  v a  2s .  c  o  m*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import ru.yandex.money.api.rights.Permission;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.HashMap;

/**
 * User: mdv
 * Date: 09.03.12
 * Time: 14:31
 */
public class YandexMoneyDroid {

    private final String clientId;

    private int activityCodeAuth;
    private DialogListener dialogListenerAuth;

    private int activityCodeHistory;
    private DialogListener dialogListenerHistory;

    private int activityCodeHistoryDetail;
    private DialogListener dialogListenerHistoryDetail;

    private int activityCodePaymentP2P;
    private DialogListener dialogListenerPaymentP2P;
    private DialogListener dialogListenerPaymentShop;
    private int activityCodePaymentShop;

    public YandexMoneyDroid(String clientId) {
        this.clientId = clientId;
    }

    public void authorize(Activity activity, int activityCode, String redirectUri,
                          Collection<Permission> permissions, boolean showResultDialog, DialogListener dialogListener) {
        authorize(activity, activityCode, redirectUri, permissions, null, showResultDialog, dialogListener);
    }

    public void authorize(Activity activity, int activityCode, String redirectUri,
            Collection<Permission> permissions, String clientSecret, boolean showResultDialog, DialogListener dialogListener) {
        activityCodeAuth = activityCode;
        dialogListenerAuth = dialogListener;
        Intent auth = IntentCreator.createAuth(activity, clientId, redirectUri, permissions, clientSecret, showResultDialog);
        activity.startActivityForResult(auth, activityCodeAuth);
    }

    public void showHistory(Activity activity, int activityCode, String accessToken, DialogListener dialogListener) {
        activityCodeHistory = activityCode;
        dialogListenerHistory = dialogListener;
        Intent history = IntentCreator.createHistory(activity, clientId, accessToken);
        activity.startActivityForResult(history, activityCodeHistory);
    }

    public void showHistoryDetail(Activity activity, int activityCode, String accessToken, String operationId,
                                  DialogListener dialogListener) {
        activityCodeHistoryDetail = activityCode;
        dialogListenerHistoryDetail = dialogListener;
        Intent historyDetail = IntentCreator.createHistoryDetail(activity, clientId, accessToken, operationId);
        activity.startActivityForResult(historyDetail, activityCodeHistoryDetail);
    }

    public void showPaymentP2P(Activity activity, int activityCode, String accessToken, String accountTo,
                               BigDecimal amount, String comment, String message, boolean showResultDialog,
                               DialogListener dialogListener) {
        activityCodePaymentP2P = activityCode;
        dialogListenerPaymentP2P = dialogListener;
        Intent intent = IntentCreator.createPaymentP2P(activity, clientId, accessToken, accountTo, amount,
                comment, message, showResultDialog);
        activity.startActivityForResult(intent, activityCodePaymentP2P);
    }
    
    public void showPaymentShop(Activity activity, int activityCode, String accessToken, BigDecimal amount,
                                String patternId, HashMap<String, String> params, boolean showResultDialog, DialogListener dialogListener) {
        activityCodePaymentShop = activityCode;
        dialogListenerPaymentShop = dialogListener;
        Intent intent = IntentCreator.createPaymentShop(activity, clientId, accessToken, amount, patternId, params,
                showResultDialog);
        activity.startActivityForResult(intent, activityCodePaymentShop);
    }

    public void callbackOnResult(int requestCode, int resultCode, Intent data) {

        boolean isSuccess = false;
        if (data != null)
            isSuccess = data.getBooleanExtra(ActivityParams.AUTH_OUT_IS_SUCCESS, false);

        if (requestCode == activityCodeAuth) {
            if (resultCode == Activity.RESULT_OK) {
                if (isSuccess)
                    dialogListenerAuth.onSuccess(data.getExtras());
            } else {
                Exception e = (Exception) data.getSerializableExtra(ActivityParams.AUTH_OUT_EXCEPTION);
                if (e == null) {
                    String error = data.getStringExtra(ActivityParams.AUTH_OUT_ERROR);
                    if (error == null) {
                        dialogListenerAuth.onCancel();
                    } else {
                        dialogListenerAuth.onFail(error);
                    }
                } else {
                    dialogListenerAuth.onException(e);
                }
            }
        }

        if (requestCode == activityCodeHistory) {
            if (resultCode == Activity.RESULT_OK) {
                if (isSuccess)
                    dialogListenerHistory.onSuccess(data.getExtras());
            } else {
                Exception e = (Exception) data.getSerializableExtra(ActivityParams.HISTORY_OUT_EXCEPTION);
                if (e == null) {
                    String error = data.getStringExtra(ActivityParams.HISTORY_OUT_ERROR);
                    if (error == null) {
                        dialogListenerHistory.onCancel();
                    } else {
                        dialogListenerHistory.onFail(error);
                    }
                } else {
                    dialogListenerHistory.onException(e);
                }
            }
        }

        if (requestCode == activityCodeHistoryDetail) {
            if (resultCode == Activity.RESULT_OK) {
                if (isSuccess)
                    dialogListenerHistoryDetail.onSuccess(data.getExtras());
            } else {
                Exception e = (Exception) data.getSerializableExtra(ActivityParams.HISTORY_DETAIL_OUT_EXCEPTION);
                if (e == null) {
                    String error = data.getStringExtra(ActivityParams.HISTORY_DETAIL_OUT_ERROR);
                    if (error == null) {
                        dialogListenerHistoryDetail.onCancel();
                    } else {
                        dialogListenerHistoryDetail.onFail(error);
                    }
                } else {
                    dialogListenerHistoryDetail.onException(e);
                }
            }
        }

        if (requestCode == activityCodePaymentP2P) {
            if (resultCode == Activity.RESULT_OK) {
                if (isSuccess)
                    dialogListenerPaymentP2P.onSuccess(data.getExtras());
            } else {
                Exception e = (Exception) data.getSerializableExtra(ActivityParams.PAYMENT_OUT_EXCEPTION);
                if (e == null) {
                    String error = data.getStringExtra(ActivityParams.PAYMENT_OUT_ERROR);
                    if (error == null) {
                        dialogListenerPaymentP2P.onCancel();
                    } else {
                        dialogListenerPaymentP2P.onFail(error);
                    }
                } else {
                    dialogListenerPaymentP2P.onException(e);
                }
            }
        }
        
        if (requestCode == activityCodePaymentShop) {
            if (resultCode == Activity.RESULT_OK) {
                if (isSuccess)
                    dialogListenerPaymentShop.onSuccess(data.getExtras());
            } else {
                Exception e = (Exception) data.getSerializableExtra(ActivityParams.PAYMENT_OUT_EXCEPTION);
                if (e == null) {
                    String error = data.getStringExtra(ActivityParams.PAYMENT_OUT_ERROR);
                    if (error == null) {
                        dialogListenerPaymentShop.onCancel();
                    } else {
                        dialogListenerPaymentShop.onFail(error);
                    }
                } else {
                    dialogListenerPaymentShop.onException(e);
                }
            }
        }
    }

    public static interface DialogListener {

        public void onSuccess(Bundle values);

        public void onFail(String cause);

        public void onException(Exception exception);

        public void onCancel();
    }
}




Java Source Code List

com.samples.client.Settings.java
com.samples.server.SampleIncomingTransferListener.java
com.samples.server.ServletListener.java
com.samples.yamodroid.Consts.java
com.samples.yamodroid.GreatAppActivity.java
ru.yandex.money.api.ApiCommandsFacadeImpl.java
ru.yandex.money.api.ApiCommandsFacade.java
ru.yandex.money.api.CommandUrlHolder.java
ru.yandex.money.api.InsufficientScopeException.java
ru.yandex.money.api.InternalServerErrorException.java
ru.yandex.money.api.InvalidTokenException.java
ru.yandex.money.api.ProtocolRequestException.java
ru.yandex.money.api.TestUrlHolder.java
ru.yandex.money.api.TokenRequesterImpl.java
ru.yandex.money.api.TokenRequester.java
ru.yandex.money.api.YamoneyAccount.java
ru.yandex.money.api.YamoneyApiClient.java
ru.yandex.money.api.YandexMoneyImpl.java
ru.yandex.money.api.YandexMoney.java
ru.yandex.money.api.enums.Destination.java
ru.yandex.money.api.enums.MoneyDirection.java
ru.yandex.money.api.enums.MoneySource.java
ru.yandex.money.api.enums.OperationHistoryType.java
ru.yandex.money.api.enums.Status.java
ru.yandex.money.api.notifications.IncomingTransferListener.java
ru.yandex.money.api.notifications.IncomingTransfer.java
ru.yandex.money.api.notifications.NotificationUtils.java
ru.yandex.money.api.notifications.NotificationsServlet.java
ru.yandex.money.api.response.AccountInfoResponse.java
ru.yandex.money.api.response.FundraisingStatsResponse.java
ru.yandex.money.api.response.OperationDetailResponse.java
ru.yandex.money.api.response.OperationHistoryResponse.java
ru.yandex.money.api.response.ProcessPaymentResponse.java
ru.yandex.money.api.response.ReceiveOAuthTokenResponse.java
ru.yandex.money.api.response.RequestPaymentResponse.java
ru.yandex.money.api.response.util.OperationHistoryError.java
ru.yandex.money.api.response.util.Operation.java
ru.yandex.money.api.response.util.PaymentErrorCode.java
ru.yandex.money.api.response.util.ProcessPaymentError.java
ru.yandex.money.api.response.util.RequestPaymentError.java
ru.yandex.money.api.response.util.money.PaymentMethods.java
ru.yandex.money.api.rights.AbstractLimitedPermission.java
ru.yandex.money.api.rights.AbstractPermission.java
ru.yandex.money.api.rights.AccountInfo.java
ru.yandex.money.api.rights.IdentifierType.java
ru.yandex.money.api.rights.MoneySource.java
ru.yandex.money.api.rights.OperationDetails.java
ru.yandex.money.api.rights.OperationHistory.java
ru.yandex.money.api.rights.PaymentP2P.java
ru.yandex.money.api.rights.PaymentShop.java
ru.yandex.money.api.rights.Payment.java
ru.yandex.money.api.rights.Permission.java
ru.yandex.money.droid.ActivityParams.java
ru.yandex.money.droid.AuthActivity.java
ru.yandex.money.droid.Consts.java
ru.yandex.money.droid.DetailHistoryActivity.java
ru.yandex.money.droid.HistoryActivity.java
ru.yandex.money.droid.HistoryAdapter.java
ru.yandex.money.droid.IntentCreator.java
ru.yandex.money.droid.LoadHistoryTask.java
ru.yandex.money.droid.PaymentActivity.java
ru.yandex.money.droid.PaymentConfirmActivity.java
ru.yandex.money.droid.PaymentShopParcelable.java
ru.yandex.money.droid.ProcessPaymentTask.java
ru.yandex.money.droid.Utils.java
ru.yandex.money.droid.YandexMoneyDroid.java