Android Open Source - cloudmine-android Base Add Payment Method Request






From Project

Back to project page cloudmine-android.

License

The source code is released under:

Copyright (c) 2012 CloudMine LLC, http://cloudmine.me Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software")...

If you think the Android project cloudmine-android 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 com.cloudmine.api.rest;
//from  w w  w.  j a  v  a  2s . co m
import com.android.volley.NetworkResponse;
import com.android.volley.Response;
import com.cloudmine.api.CMApiCredentials;
import com.cloudmine.api.CMCreditCard;
import com.cloudmine.api.CMSessionToken;
import com.cloudmine.api.rest.options.CMServerFunction;
import com.cloudmine.api.rest.response.PaymentResponse;
import me.cloudmine.annotations.Expand;
import me.cloudmine.annotations.Optional;
import me.cloudmine.annotations.Single;

import java.util.Collection;

/**
 * A Volley {@link com.android.volley.Request} for adding a payment method for a user. Requires a session token
 * <br>Copyright CloudMine LLC. All rights reserved
 * <br> See LICENSE file included with SDK for details.
 */
public class BaseAddPaymentMethodRequest extends CloudMineRequest<PaymentResponse> {
    public static final int REQUEST_TYPE = 415;

    private static final String URL = "/payments/account/methods/card";

    private static String toCreditCardArray(Collection<CMCreditCard> creditCards) {
        StringBuilder ccArray = new StringBuilder("{\"payments\":[");
        if(creditCards != null) {
            String separator = "";
            for(CMCreditCard card : creditCards) {
                ccArray.append(separator).append(card.getPaymentTransportRepresentation());
                separator = ", ";
            }
        }
        ccArray.append("]}");
        return ccArray.toString();
    }


    /**
     * Add all of the specified {@link com.cloudmine.api.CMCreditCard} to the user associated with the given {@link com.cloudmine.api.CMSessionToken}
     * @param cards A collection of the cards to add
     * @param sessionToken a valid session token. The credit cards will be added to the user whose session token this is
     * @param apiCredentials nullable CMApiCredentials to override the defaults set when the app is initialized
     * @param serverFunction A nullable server function to call after adding the credit cards to the user
     * @param successListener callback called if the call succeeds on the server
     * @param errorListener callback called if the call fails (error response from server, no Internet, some other exception)
     */
    @Expand
    public BaseAddPaymentMethodRequest(@Single Collection<CMCreditCard> cards, CMSessionToken sessionToken, @Optional CMApiCredentials apiCredentials, @Optional CMServerFunction serverFunction, Response.Listener<PaymentResponse> successListener, @Optional Response.ErrorListener errorListener) {
        super(Method.POST, URL, toCreditCardArray(cards), sessionToken, apiCredentials, serverFunction, successListener, errorListener);
    }

    @Override
    protected Response parseNetworkResponse(NetworkResponse networkResponse) {
        return Response.success(new PaymentResponse(new String(networkResponse.data), networkResponse.statusCode), getCacheEntry(networkResponse));
    }

    @Override
    public int getRequestType() {
        return REQUEST_TYPE;
    }
}




Java Source Code List

com.cloudmine.api.AccessListController.java
com.cloudmine.api.BaseCMUser.java
com.cloudmine.api.BaseCacheableCMFile.java
com.cloudmine.api.CMAndroidSocial.java
com.cloudmine.api.CMCreditCard.java
com.cloudmine.api.CMSharedPreferencesConstants.java
com.cloudmine.api.CurrentHandlerHavers.java
com.cloudmine.api.DeviceIdentifier.java
com.cloudmine.api.HasHandler.java
com.cloudmine.api.LocallySavable.java
com.cloudmine.api.db.BaseLocallySavableCMAccessList.java
com.cloudmine.api.db.BaseLocallySavableCMObject.java
com.cloudmine.api.db.CMObjectDBOpenHelper.java
com.cloudmine.api.db.LocallySavableCMGeoPoint.java
com.cloudmine.api.db.RequestConstants.java
com.cloudmine.api.db.RequestDBObject.java
com.cloudmine.api.db.RequestDBOpenHelper.java
com.cloudmine.api.db.RequestPerformerService.java
com.cloudmine.api.gui.AuthenticationDialog.java
com.cloudmine.api.gui.VolleyAuthenticationDialog.java
com.cloudmine.api.loopj.AsyncHttpClient.java
com.cloudmine.api.loopj.AsyncHttpRequest.java
com.cloudmine.api.loopj.AsyncHttpResponseHandler.java
com.cloudmine.api.loopj.PersistentCookieStore.java
com.cloudmine.api.loopj.RequestParams.java
com.cloudmine.api.loopj.RetryHandler.java
com.cloudmine.api.loopj.SerializableCookie.java
com.cloudmine.api.loopj.SimpleMultipartEntity.java
com.cloudmine.api.rest.AndroidAsynchronousHttpClient.java
com.cloudmine.api.rest.AndroidBase64Encoder.java
com.cloudmine.api.rest.AndroidHeaderFactory.java
com.cloudmine.api.rest.AndroidUserCMWebService.java
com.cloudmine.api.rest.BaseAccessListCreateRequest.java
com.cloudmine.api.rest.BaseAccessListLoadRequest.java
com.cloudmine.api.rest.BaseAccessListModificationRequest.java
com.cloudmine.api.rest.BaseAddPaymentMethodRequest.java
com.cloudmine.api.rest.BaseChangeUserIdentifierRequest.java
com.cloudmine.api.rest.BaseChangeUserPasswordRequest.java
com.cloudmine.api.rest.BaseChargeCardRequest.java
com.cloudmine.api.rest.BaseFileCreationRequest.java
com.cloudmine.api.rest.BaseFileDeleteRequest.java
com.cloudmine.api.rest.BaseFileLoadRequest.java
com.cloudmine.api.rest.BaseImageLoadRequest.java
com.cloudmine.api.rest.BaseLoadPaymentMethodsRequest.java
com.cloudmine.api.rest.BaseLoadUserProfilesRequest.java
com.cloudmine.api.rest.BaseObjectDeleteRequest.java
com.cloudmine.api.rest.BaseObjectLoadRequest.java
com.cloudmine.api.rest.BaseObjectModificationRequest.java
com.cloudmine.api.rest.BaseProfileLoadRequest.java
com.cloudmine.api.rest.BaseProfileUpdateRequest.java
com.cloudmine.api.rest.BaseRemovePaymentMethodRequest.java
com.cloudmine.api.rest.BaseResetPasswordRequest.java
com.cloudmine.api.rest.BaseSnippetRequest.java
com.cloudmine.api.rest.BaseUserCreationRequest.java
com.cloudmine.api.rest.BaseUserLoginRequest.java
com.cloudmine.api.rest.BaseUserLogoutRequest.java
com.cloudmine.api.rest.CMImageLoader.java
com.cloudmine.api.rest.CMNetwork.java
com.cloudmine.api.rest.CloudMineRequest.java
com.cloudmine.api.rest.CompleteSocialLoginRequest.java
com.cloudmine.api.rest.DialogListener.java
com.cloudmine.api.rest.DiskBitmapCache.java
com.cloudmine.api.rest.ObjectLoadRequestBuilder.java
com.cloudmine.api.rest.OkHttpStack.java
com.cloudmine.api.rest.RequestBuilder.java
com.cloudmine.api.rest.SharedRequestQueueHolders.java
com.cloudmine.api.rest.VolleyAsynchronousHttpClient.java
com.cloudmine.api.rest.callbacks.AndroidCallback.java
com.cloudmine.api.rest.callbacks.PaymentResponseCallback.java
com.cloudmine.api.rest.response.PaymentResponse.java