PinElixir.Charge

Handles the creation and retrieval of charges

Summary

Functions

Given a token, processes a previously authorized payment

Takes a map representing a customer charge to create a charge

Given a charge token returns a tuple representing the charge

Retreives all charges

Functions

capture(token)

Given a token, processes a previously authorized payment

returns a tuple

{:ok,
 %{charge: %{amount: 500, amount_refunded: 0, authorisation_expired: false,
     captured: true,
     card: %{address_city: "Hogwarts", address_country: "Straya",
       address_line1: "The Game Keepers Cottage", address_line2: nil,
       address_postcode: "H0G", address_state: "WA",
       customer_token: "cus_uie_Z4FA-FWn2hIHfTlHoA",
       display_number: "XXXX-XXXX-XXXX-0000", expiry_month: 10,
       expiry_year: 2016, name: "Rubius Hagrid", primary: true, scheme: "visa",
       token: "card_i-DSgMjhcwRi_dInriNBTw"},
     created_at: "2015-11-15T07:51:05Z", currency: "AUD",
     description: "Dragon Eggs", email: "hagrid@hogwarts.wiz",
     error_message: nil, ip_address: "127.0.0.1", merchant_entitlement: 455,
     refund_pending: false, settlement_currency: "AUD",
     status_message: "Success", success: true,
     token: "ch_NCoA7oBzrycXEPBTEUWNdQ", total_fees: 45, transfer: []}}}

OR

{:error, error_map}
create(map)

Takes a map representing a customer charge to create a charge

Can be used with a card, customer_token or card_token key

Note that amount is in the base unit of the currency, e.g $5 would be represented by an amout of 500 (cents)

charge = %{
  amount: 500,
  currency: "AUD", # Optional (default: "AUD")
  description: "Dragon Eggs",
  email: "hagrid@hogwarts.wiz",
  ip_address: "127.0.0.1",
  card: %{
    number: 4200000000000000,
    expiry_month: "10",
    expiry_year: 2016,
    cvc: 456,
    name: "Rubius Hagrid",
    address_line1: "The Game Keepers Cottage",
    address_city: "Hogwarts",
    address_postcode: "H0G",
    address_state: "WA",
    address_country: "England"
  }
}

Charge.create(charge)
charge = %{
  amount: 500,
  currency: "AUD", # Optional (default: "AUD")
  description: "Dragon Eggs",
  email: "hagrid@hogwarts.wiz",
  ip_address: "127.0.0.1"
  card_token: "abcd123"
}
Charge.create(charge)
charge = %{
  amount: 500,
  currency: "AUD", # Optional (default: "AUD")
  description: "Dragon Eggs",
  email: "hagrid@hogwarts.wiz",
  ip_address: "127.0.0.1"
  customer_token: "cust_123"
}
Charge.create(charge)

returns a tuple representing the outcome of the charge

{:ok,
 %{charge: %{amount: 500, amount_refunded: 0, authorisation_expired: false,
     captured: true,
     card: %{address_city: "Hogwarts", address_country: "Straya",
       address_line1: "The Game Keepers Cottage", address_line2: nil,
       address_postcode: "H0G", address_state: "WA",
       customer_token: "cus_uie_Z4FA-FWn2hIHfTlHoA",
       display_number: "XXXX-XXXX-XXXX-0000", expiry_month: 10,
       expiry_year: 2016, name: "Rubius Hagrid", primary: true, scheme: "visa",
       token: "card_i-DSgMjhcwRi_dInriNBTw"},
     created_at: "2015-11-15T08:33:04Z", currency: "AUD",
     description: "Dragon Eggs", email: "hagrid@hogwarts.wiz",
     error_message: nil, ip_address: "127.0.0.1", merchant_entitlement: 455,
     refund_pending: false, settlement_currency: "AUD",
     status_message: "Success", success: true,
     token: "ch_SQG0cSfE3AytQKRVAHMFNg", total_fees: 45, transfer: []}}}

OR

{:error, error_message}
get(token)

Given a charge token returns a tuple representing the charge

{:ok,
   %{charge: %{amount: 500, amount_refunded: 0, authorisation_expired: false,
       captured: true,
       card: %{address_city: "Hogwarts", address_country: "Straya",
         address_line1: "The Game Keepers Cottage", address_line2: nil,
         address_postcode: "H0G", address_state: "WA",
         customer_token: "cus_uie_Z4FA-FWn2hIHfTlHoA",
         display_number: "XXXX-XXXX-XXXX-0000", expiry_month: 10,
         expiry_year: 2016, name: "Rubius Hagrid", primary: true, scheme: "visa",
         token: "card_i-DSgMjhcwRi_dInriNBTw"},
       created_at: "2015-11-15T08:33:04Z", currency: "AUD",
       description: "Dragon Eggs", email: "hagrid@hogwarts.wiz",
       error_message: nil, ip_address: "127.0.0.1", merchant_entitlement: 455,
       refund_pending: false, settlement_currency: "AUD",
       status_message: "Success", success: true,
       token: "ch_SQG0cSfE3AytQKRVAHMFNg", total_fees: 45, transfer: []}}}

OR

{:error, error_details}
get_all()

Retreives all charges

Returns a tuple

{:ok,
 %{charges: [%{amount: 500, amount_refunded: 0, authorisation_expired: false,
      captured: true,
      card: %{address_city: "Hogwarts", address_country: "Straya",
        address_line1: "The Game Keepers Cottage", address_line2: nil,
        address_postcode: "H0G", address_state: "WA",
        customer_token: "cus_uie_Z4FA-FWn2hIHfTlHoA",
        display_number: "XXXX-XXXX-XXXX-0000", expiry_month: 10,
        expiry_year: 2016, name: "Rubius Hagrid", primary: true, scheme: "visa",
        token: "card_i-DSgMjhcwRi_dInriNBTw"},
      created_at: "2015-11-15T08:33:04Z", currency: "AUD",
      description: "Dragon Eggs", email: "hagrid@hogwarts.wiz",
      error_message: nil, ip_address: "127.0.0.1", merchant_entitlement: 455,
      refund_pending: false, settlement_currency: "AUD",
      status_message: "Success", success: true,
      token: "ch_SQG0cSfE3AytQKRVAHMFNg", total_fees: 45, transfer: []},
      %{amount: ...}],
     pagination: %{count: 42, current: 1, next: 2, pages: 2, per_page: 25,
       previous: nil}}}

OR

{:error, error_map}