/// <summary> /// Calls the api and returns an MPApiResponse. /// </summary> /// <returns>A MPAPIResponse object with the results.</returns> public static MPAPIResponse CallAPI( HttpMethod httpMethod, string path, PayloadType payloadType, JObject payload, WebHeaderCollection colHeaders, bool useCache, int requestTimeout, int retries) { var customHeaders = new Dictionary <String, String>(); foreach (var header in colHeaders) { customHeaders.Add(header.ToString(), colHeaders[header.ToString()]); } var requestOptions = new MPRequestOptions { Timeout = requestTimeout, Retries = retries, CustomHeaders = customHeaders }; return(CallAPI(httpMethod, path, payloadType, payload, useCache, requestOptions)); }
/// <summary> /// Retrieve a MPBase resource based on a specific method and configuration. /// </summary> /// <typeparam name="T">Object derived from MPBase abstract class.</typeparam> /// <param name="methodName">Name of the method we are trying to call.</param> /// <param name="useCache">Cache configuration</param> /// <param name="requestOptions">Object containing the request options.</param> /// <returns>MPBase resource.</returns> public MPBase ProcessMethod <T>(string methodName, bool useCache, MPRequestOptions requestOptions) where T : MPBase { Dictionary <string, string> mapParams = null; T resource = ProcessMethod <T>(this.GetType(), (T)this, methodName, mapParams, useCache, requestOptions); return((T)this); }
public static Card FindById(string customerId, string id, bool useCache, MPRequestOptions requestOptions) { var pathParams = new Dictionary <string, string>(); pathParams.Add("customer_id", customerId); pathParams.Add("id", id); return(ProcessMethod <Card>(typeof(Card), null, "FindById", pathParams, useCache, requestOptions)); }
internal static List <DisbursementRefund> CreateAll(long advancedPaymentId, MPRequestOptions requestOptions) { var pathParams = new Dictionary <string, string>(); pathParams.Add("advanced_payment_id", advancedPaymentId.ToString()); return(ProcessMethodBulk <DisbursementRefund>(typeof(DisbursementRefund), "CreateAll", pathParams, WITHOUT_CACHE, requestOptions)); }
/// <summary> /// Retrieve a MPBase resource based on a specfic method and configuration. /// </summary> /// <param name="methodName">Name of the method we are trying to call.</param> /// <param name="useCache">Cache configuration.</param> /// <param name="requestOptions">Object containing the request options.</param> /// <returns>MPBase resource.</returns> public static MPBase ProcessMethod(string methodName, bool useCache, MPRequestOptions requestOptions) { Type classType = GetTypeFromStack(); AdmitIdempotencyKey(classType); Dictionary <string, string> mapParams = new Dictionary <string, string>(); return(ProcessMethod <MPBase>(classType, null, methodName, mapParams, useCache, requestOptions)); }
public static bool DoCapture(long id, MPRequestOptions requestOptions) { var pathParams = new Dictionary <string, string>(); pathParams.Add("id", id.ToString()); var advancedPayment = new AdvancedPayment { Capture = true }; return(advancedPayment.ProcessMethodBool <AdvancedPayment>("DoCapture", WITHOUT_CACHE, pathParams, requestOptions)); }
public static bool Cancel(long id, MPRequestOptions requestOptions) { var pathParams = new Dictionary <string, string>(); pathParams.Add("id", id.ToString()); var advancedPayment = new AdvancedPayment { Status = "cancelled" }; return(advancedPayment.ProcessMethodBool <AdvancedPayment>("Cancel", WITHOUT_CACHE, pathParams, requestOptions)); }
/// <summary> /// Calls the api and returns an MPApiResponse. /// </summary> /// <returns>A MPAPIResponse object with the results.</returns> public static MPAPIResponse CallAPI( HttpMethod httpMethod, string path, PayloadType payloadType, JObject payload, bool useCache, MPRequestOptions requestOptions) { string cacheKey = httpMethod.ToString() + "_" + path; MPAPIResponse response = null; if (requestOptions == null) { requestOptions = new MPRequestOptions(); } if (useCache) { response = MPCache.GetFromCache(cacheKey); if (response != null) { response.IsFromCache = true; } } if (response == null) { response = new MPRESTClient().ExecuteRequest( httpMethod, path, payloadType, payload, requestOptions); if (useCache) { MPCache.AddToCache(cacheKey, response); } else { MPCache.RemoveFromCache(cacheKey); } } return(response); }
protected static List <T> ProcessMethodBulk <T>(Type clazz, string methodName, Dictionary <string, string> mapParams, bool useCache, MPRequestOptions requestOptions) where T : MPBase { //Validates the method executed if (!ALLOWED_BULK_METHODS.Contains(methodName)) { throw new MPException("Method \"" + methodName + "\" not allowed"); } var annotatedMethod = GetAnnotatedMethod(clazz, methodName); var hashAnnotation = GetRestInformation(annotatedMethod); if (requestOptions == null) { int retries = (int)hashAnnotation["retries"]; int requestTimeout = (int)hashAnnotation["requestTimeout"]; requestOptions = new MPRequestOptions { Retries = retries, Timeout = requestTimeout }; } T resource = null; HttpMethod httpMethod = (HttpMethod)hashAnnotation["method"]; PayloadType payloadType = (PayloadType)hashAnnotation["payloadType"]; string path = ParsePath(hashAnnotation["path"].ToString(), mapParams, resource, requestOptions); JObject payload = (httpMethod == HttpMethod.POST || httpMethod == HttpMethod.PUT) ? new JObject() : null; MPAPIResponse response = CallAPI(httpMethod, path, payloadType, payload, useCache, requestOptions); List <T> resourceArray = new List <T>(); if (response.StatusCode >= 200 && response.StatusCode < 300) { resourceArray = FillArrayWithResponseData <T>(clazz, response); } return(resourceArray); }
/// <summary> /// Partial payment refund /// </summary> public Payment Refund(decimal?amount, MPRequestOptions requestOptions) { Refund refund = new Refund(); refund.manualSetPaymentId((decimal)Id); refund.Amount = amount; refund.Save(requestOptions); if (refund.Id.HasValue) { var payment = Payment.FindById(Id, WITHOUT_CACHE, requestOptions); Status = payment.Status; StatusDetail = payment.StatusDetail; TransactionAmountRefunded = payment.TransactionAmountRefunded; Refunds = payment.Refunds; } else { _errors = refund.Errors; } return(this); }
/// <summary> /// Partial payment refund /// </summary> public Payment Refund(decimal?amount, MPRequestOptions requestOptions) { Refund refund = new Refund(); refund.manualSetPaymentId((decimal)_id); refund.Amount = amount; refund.Save(requestOptions); if (refund.Id.HasValue) { Thread.Sleep(500); var payment = Payment.FindById(_id, WITHOUT_CACHE, requestOptions); _status = payment.Status; _status_detail = payment.StatusDetail; _transaction_amount_refunded = payment.TransactionAmountRefunded; _refunds = payment.Refunds; } else { _errors = refund.Errors; } return(this); }
/// <summary> /// Payment refund /// </summary> public Payment Refund(MPRequestOptions requestOptions) { return(Refund(null, requestOptions)); }
public static Customer FindById(string id, bool useCache, MPRequestOptions requestOptions) { return((Customer)ProcessMethod <Customer>("FindById", id, useCache, requestOptions)); }
public static Card FindById(string customerId, string id, bool useCache, MPRequestOptions requestOptions) { return((Card)ProcessMethod <Card>(typeof(Card), "FindById", customerId, id, useCache, requestOptions)); }
public Card Update(MPRequestOptions requestOptions) { return((Card)ProcessMethod <Card>("Update", WITHOUT_CACHE, requestOptions)); }
public Refund Save(MPRequestOptions requestOptions) { return((Refund)ProcessMethod <Refund>("Save", WITHOUT_CACHE, requestOptions)); }
public static List <Card> All(String customerId, bool useCache, MPRequestOptions requestOptions) { return((List <Card>)ProcessMethodBulk <Card>(typeof(Card), "All", customerId, useCache, requestOptions)); }
public static Plan Load(string id, bool useCache, MPRequestOptions requestOptions) { return((Plan)ProcessMethod <Plan>(typeof(Plan), "Load", id, useCache, requestOptions)); }
public Plan Update(MPRequestOptions requestOptions) { return((Plan)ProcessMethod <Plan>("Update", WITHOUT_CACHE, requestOptions)); }
public static Preapproval FindById(string id, bool useCache, MPRequestOptions requestOptions) { return((Preapproval)ProcessMethod <Preapproval>(typeof(Preapproval), "FindById", id, useCache, requestOptions)); }
public Boolean Save(MPRequestOptions requestOptions) { return(ProcessMethodBool <Preapproval>("Save", WITHOUT_CACHE, requestOptions)); }
public static DiscountCampaign Find(float transactionAmount, string payerEmail, bool useCache, MPRequestOptions requestOptions) { return(Find(transactionAmount, payerEmail, null, useCache, requestOptions)); }
public static List <Payment> Search(Dictionary <string, string> filters, bool useCache, MPRequestOptions requestOptions) { return((List <Payment>)ProcessMethodBulk <Payment>(typeof(Payment), "Search", filters, useCache, requestOptions)); }
public static List <Payment> All(bool useCache, MPRequestOptions requestOptions) { return((List <Payment>)ProcessMethodBulk <Payment>(typeof(Payment), "Search", useCache, requestOptions)); }
public static DiscountCampaign Find(decimal transactionAmount, string payerEmail, string couponCode = null, bool useCache = false, MPRequestOptions requestOptions = null) { var query = CreateQuery("/v1/discount_campaigns"); query = query.Where(x => x.TransactionAmount == transactionAmount) .Where(x => x.PayerEmail == payerEmail) .Where(x => x.CouponCode == couponCode); return(query.ToList().FirstOrDefault()); }
public static DiscountCampaign Find(float transactionAmount, string payerEmail, string couponCode, bool useCache, MPRequestOptions requestOptions) { var queryParams = new Dictionary <string, string>(); queryParams.Add("transaction_amount", transactionAmount.ToString()); queryParams.Add("payer_email", payerEmail); queryParams.Add("coupon_code", couponCode); return(ProcessMethod <DiscountCampaign>(typeof(DiscountCampaign), null, "Find", queryParams, useCache, requestOptions)); }
public static Payment FindById(long?id, bool useCache, MPRequestOptions requestOptions) { return((Payment)ProcessMethod <Payment>(typeof(Payment), "FindById", id.ToString(), useCache, requestOptions)); }
public static List <Customer> Search(Dictionary <string, string> filters, bool useCache, MPRequestOptions requestOptions) { return((List <Customer>)ProcessMethodBulk <Customer>(typeof(Customer), "Search", filters, useCache, requestOptions)); }
public Boolean Update(MPRequestOptions requestOptions) { return(ProcessMethodBool <Payment>("Update", WITHOUT_CACHE, requestOptions)); }
public Customer Update(MPRequestOptions requestOptions) { return((Customer)ProcessMethod <Customer>("Update", WITHOUT_CACHE, requestOptions)); }