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

Confusing entry #278

Closed
wibed opened this issue Feb 12, 2025 · 2 comments
Closed

Confusing entry #278

wibed opened this issue Feb 12, 2025 · 2 comments

Comments

@wibed
Copy link

wibed commented Feb 12, 2025

Present examples are confusing as the object StripeEvent is missing.
ive spotted it: Sources/StripeKit/Core Resources/Events/Event.swift
from: git checkout f3ef1abca2db02b363bcccf7e527a0e2acd9baa8

but cant make out where it currently is.

creating one bloats codebase

struct Payment: Codable {
  let id: String
  let object: String  // Always "payment_intent"
  let amount: Int
  let amountCapturable: Int?
  let amountReceived: Int?
  let application: String?
  let applicationFeeAmount: Int?
  let canceledAt: Date?
  let cancellationReason: String?
  let captureMethod: String
  let clientSecret: String?
  let confirmationMethod: String
  let created: Date
  let currency: Currency
  let customer: String?
  let description: String?
  let invoice: String?
  let lastPaymentError: PaymentError?
  let livemode: Bool
  let metadata: [String: String]
  let nextAction: NextAction?
  let paymentMethod: String?
  let paymentMethodTypes: [String]
  let receiptEmail: String?
  let setup_future_usage: String?
  let shipping: Shipping?
  let status: PaymentIntentStatus
  
  enum PaymentIntentStatus: String, Codable {
    case requiresPaymentMethod = "requires_payment_method"
    case requiresConfirmation = "requires_confirmation"
    case requiresAction = "requires_action"
    case processing
    case succeeded
    case canceled
    case requiresCapture = "requires_capture"
  }
  
  struct PaymentError: Codable {
    let type: String
    let charge: String?
    let code: String
    let declineCode: String?
    let message: String
    let param: String?
  }
  
  struct NextAction: Codable {
    let type: String
    let redirectToUrl: RedirectToUrl?
    
    struct RedirectToUrl: Codable {
      let returnUrl: String
      let url: String
    }
  }
  
  struct Shipping: Codable {
    let address: Address
    let carrier: String?
    let name: String
    let phone: String?
    let trackingNumber: String?
    
    struct Address: Codable {
      let city: String?
      let country: String?
      let line1: String?
      let line2: String?
      let postalCode: String?
      let state: String?
    }
  }
}
@portellaa
Copy link

portellaa commented Feb 12, 2025

Hi @wibed

Do this:

...
import StripeKit
...


@Sendable private func someWebhook(_ request: Request) async throws -> Response {
    guard let data = request.body.data else {
      return Response(status: .badRequest)
    }

    let decoder = JSONDecoder()
    decoder.dateDecodingStrategy = .secondsSince1970
    decoder.keyDecodingStrategy = .convertFromSnakeCase

    let event = try decoder.decode(Event.self, from: data)
    request.logger.info("got event \(event)")

    return Response(status: .ok, body: Response.Body.init(string: "{received: true}"))
}

as an example

@wibed
Copy link
Author

wibed commented Feb 14, 2025

that did it thank you

@wibed wibed closed this as completed Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants