using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
namespace Retailcrm.Versions.V5
{
public partial class Client
{
///
/// Create payment
///
///
///
///
public Response PaymentsCreate(Dictionary payment, string site = "")
{
if (payment.Count < 1)
{
throw new ArgumentException("Parameter `payment` must contains a data");
}
if (!payment.ContainsKey("type"))
{
throw new ArgumentException("Parameter `type` must be set");
}
if (!payment.ContainsKey("order"))
{
throw new ArgumentException("Parameter `order` must be set");
}
return Request.MakeRequest(
"/orders/payments/create",
Request.MethodPost,
FillSite(
site,
new Dictionary
{
{ "payment", new JavaScriptSerializer().Serialize(payment) }
}
)
);
}
///
/// Update payment
///
///
///
///
///
public Response PaymentsUpdate(Dictionary payment, string by = "id", string site = "")
{
if (payment.Count < 1)
{
throw new ArgumentException("Parameter `payment` must contains a data");
}
if (!payment.ContainsKey("id") && !payment.ContainsKey("externalId"))
{
throw new ArgumentException("Parameter `payment` must contains an id or externalId");
}
CheckIdParameter(by);
string uid = by == "externalId" ? payment["externalId"].ToString() : payment["id"].ToString();
return Request.MakeRequest(
$"/orders/payments/{uid}/edit",
Request.MethodPost,
FillSite(
site,
new Dictionary
{
{ "by", by },
{ "payment", new JavaScriptSerializer().Serialize(payment) }
}
)
);
}
///
/// Delete payment
///
///
///
public Response PaymentsDelete(string id)
{
return Request.MakeRequest(
$"/orders/payments/{id}/delete",
Request.MethodPost
);
}
}
}