stark_bank v1.1.3 StarkBank.Charge View Source
Used to create and consult charges
Submodules:
- StarkBank.Charge.Customer: Used to create and consult charge customers;
- StarkBank.Charge.Log: Used to consult charge logs;
Functions:
- post
- get
- delete
- get_pdf
Link to this section Summary
Functions
Deletes the specified charges
Gets charges according to the provided parameters
Gets the specified charge PDF file content
Creates new charges. For each charge customer that is specified without an ID, the SDK will first get customers by its tax_id and, if no customers are a full match or if the 'overwrite_customer_on_mismatch' is false (default), a new customer will be created and associated with the charge. If 'overwrite_customer_on_mismatch' is true, the first retrieved customer will be overwritten with the provided customer data. Therefore, providing ID-less customers may slow the function down significantly, due to the possibly great number of subcalls to the API.
Link to this section Functions
Deletes the specified charges
Parameters:
- credentials [PID]: agent PID returned by StarkBank.Auth.login;
- charges [list of strings or StarkBank.Charge.Structs.ChargeData]: charge IDs or data structs to be deleted, e.g.: ["5718322100305920", "5705293853884416"];
Returns {:ok, deleted_charges}:
- deleted_charges [list of StarkBank.Charge.Structs.ChargeData]: deleted charges;
Example:
iex> StarkBank.Charge.delete(credentials, ["1872563178531872", charge_2, "1092381029381092", charge_4])
Gets charges according to the provided parameters
Parameters:
- credentials [PID]: agent PID returned by StarkBank.Auth.login;
options [keyword list]: refines request
- status [string]: filters specified charge status, namely: "created", "registered", "paid", "overdue", "canceled" or "failed";
- tags [list of strings]: filters charges by tags, e.g.: ["client1", "cash-in"];
- ids [list of strings or StarkBank.Charge.Structs.ChargeData]: charge IDs or data structs to be retrieved, e.g.: ["5718322100305920", "5705293853884416"];
- fields [list of strings]: selects charge data fields on API response, e.g.: ["id", "amount", "status"];
- filter_after [date or string ("%Y-%m-%d")]: only gets charges created after this date, e.g.: "2019-04-01";
- filter_before [date or string ("%Y-%m-%d")]: only gets charges created before this date, e.g.: "2019-05-01";
- limit [int]: maximum results retrieved;
Returns {:ok, retrieved_charges}:
- retrieved_charges [list of StarkBank.Charge.Structs.ChargeData]: retrieved charges;
Example:
iex> StarkBank.Charge.get(credentials, tags: ["test", "stark"], filter_after: Date.add(Date.utc_today(), -7))
Gets the specified charge PDF file content
Parameters:
- credentials [PID]: agent PID returned by StarkBank.Auth.login;
- charge [string or StarkBank.Charge.Structs.ChargeData]: charge ID or data struct, e.g.: "5718322100305920";
Returns {:ok, pdf_content}:
- pdf_content [string]: pdf file content;
Example:
iex> StarkBank.Charge.get_pdf(credentials, "1872563178531872")
iex> StarkBank.Charge.get_pdf(credentials, charge)
Creates new charges. For each charge customer that is specified without an ID, the SDK will first get customers by its tax_id and, if no customers are a full match or if the 'overwrite_customer_on_mismatch' is false (default), a new customer will be created and associated with the charge. If 'overwrite_customer_on_mismatch' is true, the first retrieved customer will be overwritten with the provided customer data. Therefore, providing ID-less customers may slow the function down significantly, due to the possibly great number of subcalls to the API.
Parameters:
- credentials [PID]: agent PID returned by StarkBank.Auth.login;
- charges [list of StarkBank.Charge.Structs.ChargeData]: charge structs;
options [keyword list]: refines request
- overwrite_customer_on_mismatch [bool, default false]: if true, first mismatching customer will be overwritten, if any; if false, new customer will be created (only active if no matching customers are located)
- discount [int]: defines discount in cents if charge is paid before discountDate (if discount is defined, discountDate must also be defined)
- discount_date [date or string ("%Y-%m-%d")]: defines up to when the defined discount will be valid (if discount is defined, discountDate must also be defined)
Returns {:ok, posted_charges}:
- posted_charges [list of StarkBank.Charge.Structs.ChargeData]: posted charges;
Example:
iex> StarkBank.Charge.post(credentials, [charge_1, charge_2])