Skip to content

Commit

Permalink
clear errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raquentin committed May 21, 2024
1 parent 5ee9598 commit ab6f25d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 60 deletions.
35 changes: 0 additions & 35 deletions src/stripe.gleam
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import gleam/http.{type Header, Get}
import gleam/http/request
import gleam/http/response
import gleam/httpc
import gleam/result

import stripe/error

pub type ApiKey =
String

Expand All @@ -16,30 +8,3 @@ pub opaque type StripeClient {
pub fn new(api_key: ApiKey) -> StripeClient {
StripeClient(api_key)
}

fn headers(client: StripeClient) -> List(Header) {
[
#("Authorization", "Bearer " <> client.api_key),
#("Content-Type", "application/json"),
]
}

fn send_request(
client: StripeClient,
method: http.Method,
path: String,
params: List(#(String, String)),
) -> Result(String, StripeError) {
let url = "https://api.stripe.com/v1/" <> path
let body = http.url_encode(params)

let assert Ok(request) =
http.Request(method: method, url: url, headers: headers(client), body: body)

use response <- result.try(httpc.send(request))

case response.status {
200 -> Ok(response.body)
_ -> StripeError()
}
}
54 changes: 29 additions & 25 deletions src/stripe/customer.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//// The [`Customer`] type, associated types, and associated functions.
//// All implementations as per https://stripe.com/docs/api/customers.

import gleam/dict.{type Dict}
import gleam/option.{type Option}

pub type Address {
Address(
city: Option(String),
Expand Down Expand Up @@ -33,13 +36,20 @@ pub type Shipping {
Shipping(address: Address, name: String, phone: Option(String))
}

pub type CashBalanceSettings {
CashBalanceSettings(
reconciliation_mode: ReconiliationMode,
using_merchant_default: Bool,
)
}

pub type CashBalance {
CashBalance(
object: String,
available: Option(String),
customer: String,
livemode: bool,
settings: CashBalanaceSettings,
livemode: Bool,
settings: CashBalanceSettings,
)
}

Expand All @@ -48,13 +58,6 @@ pub type ReconiliationMode {
Manual
}

pub type CashBalanceSettings {
CashBalanceSettings(
reconciliation_mode: ReconiliationMode,
using_merchant_default: bool,
)
}

pub type CouponAppliesTo {
List(String)
}
Expand All @@ -81,17 +84,17 @@ pub type Coupon {
applies_to: Option(CouponAppliesTo),
created: Timestamp,
currency: Option(Currency),
currency_options: Option(Map(Currency, CurrencyOption)),
currency_options: Option(Dict(Currency, CurrencyOption)),
duration: Duration,
duration_in_months: Option(Int),
livemode: bool,
livemode: Bool,
max_redemptions: Option(Int),
metadata: Option(Map(String, String)),
metadata: Option(Dict(String, String)),
name: Option(String),
percent_off: Option(Float),
redeem_by: Option(Timestamp),
times_redeemed: Int,
valid: bool,
valid: Bool,
)
}

Expand Down Expand Up @@ -132,16 +135,16 @@ pub type Source {
customer: Option(String),
fingerprint: Option(String),
last4: String,
metadata: Option(Map(String, String)),
metadata: Option(Dict(String, String)),
routing_number: Option(String),
status: String,
has_more: bool,
has_more: Bool,
url: String,
)
}

pub type Sources {
Sources(object: String, data: List(Source), has_more: bool, url: String)
Sources(object: String, data: List(Source), has_more: Bool, url: String)
}

pub type AutomaticTax {
Expand Down Expand Up @@ -177,7 +180,7 @@ pub type TaxExempt {
pub type TaxIdOwnerType {
Account
Application
Customer
CustomerType
Self
}

Expand Down Expand Up @@ -253,15 +256,16 @@ pub type TaxIdType {
VeRif
VnTin
ZaVat
Unknown // For legacy tax IDs with type unknown
Unknown
// For legacy tax IDs with type unknown
}

pub type TaxIdOwner {
Owner(
account: Option(String),
application: Option(String),
customer: Option(String),
type: TaxIdOwnerType,
type_: TaxIdOwnerType,
)
}

Expand All @@ -287,16 +291,16 @@ pub type TaxId {
country: Option(String),
created: Timestamp,
customer: Option(String),
livemode: bool,
livemode: Bool,
owner: Option(TaxIdOwner),
type: TaxIdType,
type_: TaxIdType,
value: String,
verification: Option(TaxIdVerification),
)
}

pub type TaxIds {
TaxIds(object: String, data: List(TaxId), has_more: bool, url: String)
TaxIds(object: String, data: List(TaxId), has_more: Bool, url: String)
}

pub type Customer {
Expand All @@ -309,15 +313,15 @@ pub type Customer {
created: Int,
currency: Option(String),
default_source: Option(String),
delinquent: bool,
delinquent: Bool,
description: Option(String),
discount: Option(Discount),
email: Option(String),
invoice_prefix: Option(String),
invoice_settings: Option(InvoiceSettings),
livemode: false,
livemode: Bool,
// TODO: metadata more generic?
metadata: Option(Map(String, String)),
metadata: Option(Dict(String, String)),
name: Option(String),
next_invoice_sequence: Option(Int),
phone: Option(String),
Expand Down

0 comments on commit ab6f25d

Please sign in to comment.