/// <summary> /// Cancels a previously created subscription plan. /// </summary> /// <param name="planId">The unique identifier for the subscription plan.</param> /// <returns>A "CancelPlanResponse" object, containing the response from the NETELLER REST API.</returns> public static CancelPlanResponse CacelPlan(string planId) { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; string path = "v1/plans/" + planId + "/cancel"; string response = api.Post(path, null, headers, null); DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (CancelPlanResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); CancelPlanResponse responseObject = (CancelPlanResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Cancels a previously created subscription. /// </summary> /// <param name="subscriptionId">The unique identifier for the subscription.</param> /// <param name="expand">Expands the specified resource. Possible values: "plan, customer"</param> /// <returns>A "CancelSubscriptionResponse" object, containing the response from the NETELLER REST API.</returns> public static CancelSubscriptionResponse CancelSubscription(string subscriptionId, string expand = "") { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; string path = "v1/subscriptions/" + subscriptionId + "/cancel"; string response; if (!String.IsNullOrEmpty(expand)) { Dictionary<string, string> queryParams = new Dictionary<string, string> { {"expand", expand} }; response = api.Post(path, queryParams, headers, null); } else { response = api.Post(path, null, headers, null); } DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (CancelSubscriptionResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); CancelSubscriptionResponse responseObject = (CancelSubscriptionResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Makes a request to the NETELLER REST API to exchange the authorization code for a new access token and refresh token. /// </summary> /// <param name="authCode">The authorization code obtained from the authorization flow.</param> /// <param name="redirectUri">The redirect_uri used in the authorization flow. This value must match the uri used to obtain authorization, If not supplied during the authorization flow then the redirect_uri will be the registered redirect uri for your application (as set in the merchant.com portal under the APPS section) and should not be passed.</param> /// <returns>Returns a new access token of type "auth_code".</returns> public Token getToken_authCode(string authCode, string redirectUri = "") { NetellerApi api = new NetellerApi(); Dictionary<string, string> queryParams = new Dictionary<string, string> { {"grant_type", "authorization_code"}, {"code", authCode} }; if (!String.IsNullOrEmpty(redirectUri)) { queryParams.Add("redirect_uri", redirectUri); } Byte[] plainTextCredentials = Encoding.UTF8.GetBytes(ClientId + ":" + ClientSecret); string base64EncodedCredentials = Convert.ToBase64String(plainTextCredentials); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Basic " + base64EncodedCredentials} }; const string path = "v1/oauth2/token"; string response = api.Post(path, queryParams, headers, null); DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (Token)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); Token responseObject = (Token) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Creates a new outgoing payment. /// </summary> /// <param name="request">A "TransferOutRequest" object containing the required data to be send to the API.</param> /// <returns>A "TransferOutResponse" object, containing the response from the NETELLER REST API.</returns> /// <param name = "expand">Expands the specified resource. Possible values: "customer"</param> public static TransferOutResponse TransferOut(TransferOutRequest request, string expand = "") { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; Dictionary<string, string> queryParams = new Dictionary<string, string>(); if (!String.IsNullOrEmpty(expand)) { queryParams.Add("expand",expand); } DataContractJsonSerializer requestSerializer = new DataContractJsonSerializer(typeof (TransferOutRequest)); MemoryStream requestMemoryStream = new MemoryStream(); requestSerializer.WriteObject(requestMemoryStream, request); string requestJson = Encoding.UTF8.GetString(requestMemoryStream.ToArray()); const string path = "v1/transferOut"; string response = api.Post(path, queryParams, headers, requestJson); DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (TransferOutResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); TransferOutResponse responseObject = (TransferOutResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Look up details about a payment invoice issued for an order. /// </summary> /// <param name="orderId">The unique identifier for the order. (ie: ORD_7915d463-ccc8-4305-9d33-9e5c9310f12e)</param> /// <returns>A "LookupOrderInvoiceResponse" object, containing the response from the NETELLER REST API.</returns> public static LookupOrderInvoiceResponse LookupOrderInvoice(string orderId) { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; string path = "v1/orders/" + orderId + "/invoice"; string response = api.Get(path, null, headers); DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (LookupOrderInvoiceResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); LookupOrderInvoiceResponse responseObject = (LookupOrderInvoiceResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Looks up a payment by provided merchantRefId or transactionId. /// </summary> /// <param name="merchantRefId">Your unique identifier for this transaction that was supplied on your original request.</param> /// <param name="transactionId">The unique identifier for the transaction.</param> /// <param name="expand">Expands the specified resource. Possible values: "customer"</param> /// <returns>A "LookupPaymentResponse" object, containing the response from the NETELLER REST API.</returns> public static LookupPaymentResponse LookupPayment(string merchantRefId = "", string transactionId = "", string expand = "") { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; string response = ""; if (!String.IsNullOrEmpty(merchantRefId)) { string path = "v1/payments/" + merchantRefId; Dictionary<string, string> queryParams = new Dictionary<string, string> { {"refType", "merchantRefId"} }; if (!String.IsNullOrEmpty(expand)) { queryParams.Add("expand", expand); } response = api.Get(path, queryParams, headers); } else if (!String.IsNullOrEmpty(transactionId)) { string path = "v1/payments/" + transactionId; Dictionary<string, string> queryParams = new Dictionary<string, string>(); if (!String.IsNullOrEmpty(expand)) { queryParams.Add("expand", expand); } response = api.Get(path, queryParams, headers); } DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (LookupPaymentResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); LookupPaymentResponse responseObject = (LookupPaymentResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Lookup details for a specific customer. /// </summary> /// <param name="customerId">The unique identifier for the customer.</param> /// <param name="email">The customer's NETELLER registered Email</param> /// <param name="accountId">The customer's NETELLER Account ID.</param> /// <returns>A "LookupCustomerResponse" object, containing the response from the NETELLER REST API.</returns> public static LookupCustomerResponse LookupCustomer(string customerId = "", string email = "", string accountId = "") { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; string response = ""; if (!String.IsNullOrEmpty(customerId)) { string path = "v1/customers/" + customerId; response = api.Get(path, null, headers); } else if (!String.IsNullOrEmpty(email)) { const string path = "v1/customers"; Dictionary<string, string> queryParams = new Dictionary<string, string> { {"email", email} }; response = api.Get(path, queryParams, headers); } else if (!String.IsNullOrEmpty(accountId)) { const string path = "v1/customers"; Dictionary<string, string> queryParams = new Dictionary<string, string> { {"accountId", accountId} }; response = api.Get(path, queryParams, headers); } DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (LookupCustomerResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); LookupCustomerResponse responseObject = (LookupCustomerResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Lists all previously created subscriptions. /// </summary> /// <param name="limit">Sets the number of records to be returned.</param> /// <param name="offset">Sets the results offset.</param> /// <returns>A "ListSubscriptionsResponse" object, containing the response from the NETELLER REST API.</returns> public static ListSubscriptionsResponse ListSubscriptions(string limit = "", string offset = "") { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; const string path = "v1/subscriptions"; Dictionary<string, string> queryParams = new Dictionary<string, string>(); if (!String.IsNullOrEmpty(limit)) { queryParams.Add("limit", limit); } if (!String.IsNullOrEmpty(offset)) { queryParams.Add("offset", offset); } string response = api.Get(path, queryParams, headers); DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (ListSubscriptionsResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); ListSubscriptionsResponse responseObject = (ListSubscriptionsResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Deletes a previously created subscription plan. /// </summary> /// <param name="planId">The unique identifier for the subscription plan.</param> public static void DeletePlan(string planId) { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; string path = "v1/plans/" + planId; api.Delete(path, null, headers, null); }
/// <summary> /// Enrolls an existing NETELLER account holder in one of your subscription plans. /// </summary> /// <param name="request">A "CreateSubscriptionRequest" object containing the required data to be send to the API.</param> /// <param name="token">An access token of type "auth_code", authorized by the account holder.</param> /// <returns>A "CreateSubscriptionResponse" object, containing the response from the NETELLER REST API.</returns> /// <param name = "expand">Expands the specified resource. Possible values: "plan, customer"</param> public static CreateSubscriptionResponse CreateSubscription(CreateSubscriptionRequest request, string token, string expand = "") { NetellerApi api = new NetellerApi(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token} }; Dictionary<string, string> queryParams = new Dictionary<string, string>(); if (!String.IsNullOrEmpty(expand)) { queryParams.Add("expand",expand); } const string path = "v1/subscriptions"; DataContractJsonSerializer requestSerializer = new DataContractJsonSerializer(typeof (CreateSubscriptionRequest)); MemoryStream requestMemoryStream = new MemoryStream(); requestSerializer.WriteObject(requestMemoryStream, request); string requestJson = Encoding.UTF8.GetString(requestMemoryStream.ToArray()); string response = api.Post(path, queryParams, headers, requestJson); DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (CreateSubscriptionResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); CreateSubscriptionResponse responseObject = (CreateSubscriptionResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }
/// <summary> /// Creates a subscription plan. /// </summary> /// <param name="request">A "CreatePlanRequest" object containing the required data to be send to the API.</param> /// <returns>A "CreatePlanResponse" object, containing the response from the NETELLER REST API.</returns> public static CreatePlanResponse CreatePlan(CreatePlanRequest request) { NetellerApi api = new NetellerApi(); Token token = api.getToken_clientCredentials(); Dictionary<string, string> headers = new Dictionary<string, string> { {"Authorization", "Bearer " + token.accessToken} }; DataContractJsonSerializer requestSerializer = new DataContractJsonSerializer(typeof (CreatePlanRequest)); MemoryStream requestMemoryStream = new MemoryStream(); requestSerializer.WriteObject(requestMemoryStream, request); string requestJson = Encoding.UTF8.GetString(requestMemoryStream.ToArray()); const string path = "vi/plans"; string response = api.Post(path, null, headers, requestJson); DataContractJsonSerializer responseSerializer = new DataContractJsonSerializer(typeof (CreatePlanResponse)); MemoryStream responseMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(response)); CreatePlanResponse responseObject = (CreatePlanResponse) responseSerializer.ReadObject(responseMemoryStream); return responseObject; }