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;
//fromwww.java2s.comimport 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.
*/publicclass BaseAddPaymentMethodRequest extends CloudMineRequest<PaymentResponse> {
publicstaticfinalint REQUEST_TYPE = 415;
privatestaticfinal String URL = "/payments/account/methods/card";
privatestatic 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
publicint getRequestType() {
return REQUEST_TYPE;
}
}