Skip to content

StripeKit 18.0.0 async await support

Compare
Choose a tag to compare
@Andrewangeta Andrewangeta released this 18 May 16:14
· 37 commits to main since this release
c558b4b

What's Changed

Async Await

All APIs use async await which means the minimum swift version is now 5.7

// Before:
stripe.refunds.create(charge: "ch_12345", reason: .requestedByCustomer).map { ... } 
// After: 
try await stripe.refunds.create(charge: "ch_12345", reason: .requestedByCustomer)

Modifying headers per request

Before:

stripe = StripeClient(...)
stripe.refunds.headers.add(name: "Stripe-Account", value: "acc_12345")
stripe.refunds.create(charge: "ch_12345", reason: .requestedByCustomer)

After:

stripe = StripeClient(...)
stripe.refunds
.addHeaders(["Stripe-Account": "acc_12345",
             "Authorization": "Bearer different_api_key",
             "Stripe-Version": "older-api-version"])
.create(charge: "ch_12345", reason: .requestedByCustomer)

Cleaner type names and public initializers

Remove the Stripe prefix from resources/models as well as make their inits public.
This helps a lot when unit testing to create Stripe types without having to setup a dictionary to use the decoding initializer:

// Before:
let connectProperties = ["id": "acct_1234",
                         "object": "account",
                         "created": Int(Date().timeIntervalSince1970)].toData()
    
    let decoder = JSONDecoder()
    decoder.dateDecodingStrategy = .secondsSince1970
    decoder.keyDecodingStrategy = .convertFromSnakeCase

    return try decoder.decode(StripeConnectAccount.self, from: connectProperties)
    
// After: 
return ConnectAccount(id: "acct_1234", object: "account", created: Int(Date().timeIntervalSince1970))