Omise.Schedule (omise v0.10.0)
Provides Schedule API interfaces.
Summary
Functions
Create a schedule.
Destroy a schedule.
List all schedules.
List all occurrences of a schedule.
Retrieve a schedule.
Types
@type t() :: %Omise.Schedule{ active: boolean(), charge: map(), created: String.t(), deleted: boolean(), end_date: String.t(), end_on: String.t(), ended_at: String.t(), every: integer(), id: String.t(), in_words: String.t(), livemode: boolean(), location: String.t(), next_occurrence_dates: list(), object: String.t(), occurrences: Omise.List.t(), on: map(), period: String.t(), start_date: String.t(), status: String.t(), transfer: term() }
Functions
Link to this function
create(params, opts \\ [])
@spec create(Keyword.t(), Keyword.t()) :: {:ok, t()} | {:error, Omise.Error.t()}
Create a schedule.
Returns {:ok, schedule}
if the request is successful, {:error, error}
otherwise.
Request Parameters:
every
- How often the schedule runs. E.g.: Every3
weeks.period
-day
,week
ormonth
. E.g.: Every 3week
s.on
- This hash keys depend on the period.start_date
- (optional) When the schedule should start, in ISO 8601 format (YYYY-MM-DD). Defaults to today.end_date
- When the schedule should end, in ISO 8601 format (YYYY-MM-DD).capture
- (optional) Whether or not you want the charge to be captured right away, when not specified it is set to true.charge
- A charge map. (for charge schedule)transfer
- A transfer map. (for transfer schedule)
Examples
# Charge a specific customer card every 2 days
Omise.Schedule.create(
every: 2,
period: "day",
start_date: "2017-06-5",
end_date: "2018-05-01",
charge: [
customer: "cust_test_55c6cjwyr9kl4rt4jso",
amount: 199_00,
description: "Membership fee",
]
)
# Charge every Monday and Friday
Omise.Schedule.create(
every: 1,
period: "week",
on: [
weekdays: ["monday", "friday"]
],
start_date: "2017-06-5",
end_date: "2018-05-01",
charge: [
customer: "cust_test_55c6cjwyr9kl4rt4jso",
amount: 199_00,
description: "Membership fee",
]
)
# Charge on the 1st, 10th and 15th every 3 months
Omise.Schedule.create(
every: 3,
period: "month",
on: [
days_of_month: [1, 10, 15]
],
start_date: "2017-06-5",
end_date: "2018-05-01",
charge: [
customer: "cust_test_55c6cjwyr9kl4rt4jso",
amount: 199_00,
description: "Membership fee",
]
)
# Charge on the 2nd Monday every month
Omise.Schedule.create(
every: 1,
period: "month",
on: [
weekday_of_month: "second_monday"
],
start_date: "2017-06-5",
end_date: "2018-05-01",
charge: [
customer: "cust_test_55c6cjwyr9kl4rt4jso",
amount: 199_00,
description: "Membership fee",
]
)
# Transfer a fixed amount every 2 days
Omise.Schedule.create(
every: 2,
period: "day",
start_date: "2017-07-8",
end_date: "2017-07-31",
transfer: [
recipient: "recp_test_55j2an6c8fd07xbccd3",
amount: 100_00_00,
]
)
# Transfer a percentage of the balance every Monday and Friday
Omise.Schedule.create(
every: 1,
period: "week",
on: [
weekdays: ["monday", "friday"],
],
start_date: "2017-07-8",
end_date: "2017-07-31",
transfer: [
recipient: "recp_test_556jkf7u174ptxuytac",
percentage_of_balance: 75,
]
)
Link to this function
destroy(id, opts \\ [])
@spec destroy(String.t(), Keyword.t()) :: {:ok, t()} | {:error, Omise.Error.t()}
Destroy a schedule.
Returns {:ok, schedule}
if the request is successful, {:error, error}
otherwise.
Examples
Omise.Schedule.destroy("schd_test_584yqgiuavbzrfng7mv")
Link to this function
list(params \\ [], opts \\ [])
@spec list(Keyword.t(), Keyword.t()) :: {:ok, Omise.List.t()} | {:error, Omise.Error.t()}
List all schedules.
Returns {:ok, schedules}
if the request is successful, {:error, error}
otherwise.
Query Parameters:
offset
- (optional, default: 0) The offset of the first record returned.limit
- (optional, default: 20, maximum: 100) The maximum amount of records returned.from
- (optional, default: 1970-01-01T00:00:00Z, format: ISO 8601) The UTC date and time limiting the beginning of returned records.to
- (optional, default: current UTC Datetime, format: ISO 8601) The UTC date and time limiting the end of returned records.
Examples
Omise.Schedule.list(limit: 10)
Link to this function
list_occurrences(id, params \\ [], opts \\ [])
@spec list_occurrences(String.t(), Keyword.t(), Keyword.t()) :: {:ok, Omise.List.t()} | {:error, Omise.Error.t()}
List all occurrences of a schedule.
Returns {:ok, occurrences}
if the request is successful, {:error, error}
otherwise.
Query Parameters:
offset
- (optional, default: 0) The offset of the first record returned.limit
- (optional, default: 20, maximum: 100) The maximum amount of records returned.from
- (optional, default: 1970-01-01T00:00:00Z, format: ISO 8601) The UTC date and time limiting the beginning of returned records.to
- (optional, default: current UTC Datetime, format: ISO 8601) The UTC date and time limiting the end of returned records.
Examples
Omise.Schedule.list_occurrences("schd_test_584yqgiuavbzrfng7mv")
Link to this function
retrieve(id, opts \\ [])
@spec retrieve(String.t(), Keyword.t()) :: {:ok, t()} | {:error, Omise.Error.t()}
Retrieve a schedule.
Examples
Omise.Schedule.retrieve("schd_test_5850ga4l8a6r6bgj4oj")