Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to async await #152

Merged
merged 65 commits into from
May 18, 2023
Merged

Update to async await #152

merged 65 commits into from
May 18, 2023

Conversation

Andrewangeta
Copy link
Member

@Andrewangeta Andrewangeta commented Oct 30, 2022

This PR has a few goals for updating to async await APIs and making certain actions easier to do.
A few key areas of focus:

Async Await

Converting all APIs to use async await which means bumping the swift tools version to 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))   

What's Been converted

Core Resources

  • Balance
  • Balance Transactions
  • Charges
  • Customers
  • Disputes
  • Events
  • Files
  • File Links
  • Mandates
  • PaymentIntents
  • SetupIntents
  • SetupAttempts
  • Payouts
  • Refunds
  • Tokens

Payment Methods

  • Payment Methods
  • Bank Accounts
  • Cards
  • Sources

Products

  • Products
  • Prices
  • Coupons
  • Promotion Codes
  • Discounts
  • Tax Codes
  • Tax Rates
  • Shipping Rates

Checkout

  • Sessions

Billing

  • Credit Notes
  • Customer Balance Transactions
  • Customer Portal
  • Customer Tax IDs
  • Invoices
  • Invoice Items
  • Plans
  • Quotes
  • Quote Line Items
  • Subscriptions
  • Subscription items
  • Subscription Schedule
  • Test Clocks
  • Usage Records

Connect

  • Account
  • Account Links
  • Account Sessions
  • Application Fees
  • Application Fee Refunds
  • Capabilities
  • Country Specs
  • External Accounts
  • Persons
  • Top-ups
  • Transfers
  • Transfer Reversals
  • Secret Manager

Fraud

  • Early Fraud Warnings
  • Reviews
  • Value Lists
  • Value List Items

Issuing

  • Authorizations
  • Cardholders
  • Cards
  • Disputes
  • Funding Instructions
  • Transactions

Terminal

  • Connection Tokens
  • Locations
  • Readers
  • Hardware Orders
  • Hardware Products
  • Hardware SKUs
  • Hardware Shipping Methods
  • Configurations

Sigma

  • Scheduled Queries

Reporting

  • Report Runs
  • Report Types

Identity

  • VerificationSessions
  • VerificationReports

Webhooks

  • Webhook Endpoints
  • Signature Verification

@Andrewangeta Andrewangeta marked this pull request as draft October 30, 2022 18:15
This was referenced Feb 1, 2023
Andrewangeta and others added 7 commits February 4, 2023 14:40
* Renamed StripeCurrency to Currency

* Updated address

* Update expandable to have multiple inits.

* Updated charge properties and renamed

* Added extension for sending requests using strings

* Updated charge routes and charge list.
* Renamed Deleted Object.

* Added init for DynamicExpandable

* Renamed StripeCustomer

* Updated Customer and routes

* Fix search path for charges API
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
* Disable tests for now.

* Added http body extension for data.

* Renamed StripeFile.

* Updated file and file link routes.
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
* Renamed Payment intent

* Updated payment intent models.

* Updated and added payment intent routes.
Copy link
Member

@gwynne gwynne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks

.github/workflows/test.yml Outdated Show resolved Hide resolved
Tests/StripeKitTests/ExpandableTests.swift Show resolved Hide resolved
gwynne and others added 10 commits March 14, 2023 18:51
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
Co-authored-by: Andrew Edwards <andrew.edwards@saks.com>
@Andrewangeta Andrewangeta marked this pull request as ready for review May 18, 2023 15:54
@Andrewangeta
Copy link
Member Author

Addresses #34 #153 #157 #163 #146 #150 #168

@Andrewangeta Andrewangeta merged commit c558b4b into main May 18, 2023
@Andrewangeta Andrewangeta deleted the async-await branch May 18, 2023 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants