-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChargeMobileMoneyRepository.swift
More file actions
33 lines (26 loc) · 1.43 KB
/
Copy pathChargeMobileMoneyRepository.swift
File metadata and controls
33 lines (26 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Foundation
import PaystackCore
protocol ChargeMobileMoneyRepository {
func chargeMobileMoney(phone: String, transactionId: String, provider: String) async throws -> MobileMoneyTransaction
func listenForMobileMoneyResponse(for transactionId: Int) async throws -> ChargeCardTransaction
func checkPendingCharge(with accessCode: String) async throws -> ChargeCardTransaction
}
struct ChargeMobileMoneyRepositoryImplementation: ChargeMobileMoneyRepository {
let paystack: Paystack
init() {
self.paystack = PaystackContainer.instance.retrieve()
}
func chargeMobileMoney(phone: String, transactionId: String, provider: String) async throws -> MobileMoneyTransaction {
let request = MobileMoneyData(phone: phone, transaction: transactionId, provider: provider)
let response = try await paystack.chargeMobileMoney(with: request).async()
return MobileMoneyTransaction.from(response)
}
func listenForMobileMoneyResponse(for transactionId: Int) async throws -> ChargeCardTransaction {
let response = try await paystack.listenForMobileMoneyResponse(for: transactionId).async()
return ChargeCardTransaction.from(response)
}
func checkPendingCharge(with accessCode: String) async throws -> ChargeCardTransaction {
let response = try await paystack.checkPendingCharge(forAccessCode: accessCode).async()
return ChargeCardTransaction.from(response)
}
}