-
Notifications
You must be signed in to change notification settings - Fork 0
MOB-875 Adding MobileMoney Charge endpoint #101
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
base: main
Are you sure you want to change the base?
Changes from all commits
dbc83e0
49156d4
570ca66
cb4ab6b
9054f47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
|
||
protocol MobileMoneyService: PaystackService { | ||
func postChargeMobileMoney(_ request: MobileMoneyChargeRequest) -> Service<MobileMoneyChargeResponse> | ||
} | ||
|
||
struct MobileMoneyServiceImplementation: MobileMoneyService { | ||
|
||
var config: PaystackConfig | ||
|
||
var parentPath: String { | ||
return "charge" | ||
} | ||
|
||
func postChargeMobileMoney(_ request: MobileMoneyChargeRequest) -> Service<MobileMoneyChargeResponse> { | ||
return post("/mobile_money", request) | ||
.asService() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foundation | ||
|
||
// MARK: - MobileMoney | ||
public struct MobileMoney: Codable { | ||
let key: String | ||
let value: String | ||
let isNew: Bool | ||
let phoneNumberRegex: String | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
// MARK: - MobileMoneyChargeRequest | ||
struct MobileMoneyChargeRequest: Codable { | ||
let channelName: String | ||
let amount: Int | ||
let email: String | ||
let phone: String | ||
let transaction: String | ||
let provider: String | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
|
||
// MARK: - MobileMoneyChargeResponse | ||
public struct MobileMoneyChargeResponse: Codable { | ||
let status: Bool | ||
let message: String | ||
let data: MobileMoneyChargeData | ||
} | ||
|
||
// MARK: - MobileMoneyChargeData | ||
public struct MobileMoneyChargeData: Codable { | ||
let transaction: String | ||
let phone: String | ||
let provider: String | ||
let channelName: String | ||
let display: Display | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case transaction | ||
case phone | ||
case provider | ||
case channelName | ||
case display | ||
} | ||
} | ||
|
||
// MARK: - Display | ||
public struct Display: Codable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Peter-John-paystack The name should probably have a "MobileMoney" prefix to tie it more to the channel since we don't know if there'll be another "Display" object in the near future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we could make it a child of the MobileMoneyChargeData struct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I can still make that change @michael-paystack Good catch. |
||
let type: String | ||
let message: String | ||
let timer: Int | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
|
||
public struct MobileMoneyData: Equatable { | ||
let channelName: String | ||
let amount: Int | ||
let email: String | ||
let phone: String | ||
let transaction: String | ||
let provider: String | ||
|
||
public init(channelName: String, amount: Int, email: String, phone: String, transaction: String, provider: String) { | ||
self.channelName = channelName | ||
self.amount = amount | ||
self.email = email | ||
self.phone = phone | ||
self.transaction = transaction | ||
self.provider = provider | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// swiftlint:disable file_length type_body_length line_length | ||
Peter-John-paystack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import XCTest | ||
@testable import PaystackCore | ||
|
||
|
@@ -27,6 +28,21 @@ final class ChargeTests: PSTestCase { | |
_ = try serviceUnderTest.authenticateCharge(withOtp: "12345", accessCode: "abcde").sync() | ||
} | ||
|
||
func testMobileMoneyCharge() throws { | ||
let mobileMoneyRequestBody = MobileMoneyChargeRequest(channelName: "MOBILE_MONEY_1504248187", amount: 1000, email: "[email protected]", phone: "0723362418", transaction: "1504248187", provider: "MPESA") | ||
|
||
mockServiceExecutor | ||
.expectURL("https://api.paystack.co/charge/mobile_money") | ||
.expectMethod(.post) | ||
.expectHeader("Authorization", "Bearer \(apiKey)") | ||
.expectBody(mobileMoneyRequestBody) | ||
.andReturn(json: "ChargeMobileMoneyResponse") | ||
|
||
let mobileMoneyData = MobileMoneyData(channelName: "MOBILE_MONEY_1504248187", amount: 1000, email: "[email protected]", phone: "0723362418", transaction: "1504248187", provider: "MPESA") | ||
|
||
_ = try serviceUnderTest.chargeMobileMoney(with: mobileMoneyData).sync() | ||
} | ||
|
||
func testAuthenticateChargeWithPhoneAuthentication() throws { | ||
let phoneRequestBody = SubmitPhoneRequest(phone: "0111234567", accessCode: "abcde") | ||
|
||
|
@@ -90,4 +106,20 @@ final class ChargeTests: PSTestCase { | |
_ = try serviceUnderTest.listenFor3DSResponse(for: transactionId).sync() | ||
} | ||
|
||
func testListenForMobileMoney() throws { | ||
let transactionId = 1234 | ||
let mockSubscription = PusherSubscription(channelName: "MOBILE_MONEY_\(transactionId)", | ||
eventName: "response") | ||
|
||
// swiftlint:disable:next line_length | ||
let responseString = "{\"redirecturl\":\"?trxref=2wdckavunc&reference=2wdckavunc\",\"trans\":\"1234\",\"trxref\":\"2wdckavunc\",\"reference\":\"2wdckavunc\",\"status\":\"success\",\"message\":\"Success\",\"response\":\"Approved\"}" | ||
|
||
mockSubscriptionListener | ||
.expectSubscription(mockSubscription) | ||
.andReturnString(responseString) | ||
|
||
_ = try serviceUnderTest.listenForMobileMoneyResponse(for: transactionId).sync() | ||
} | ||
|
||
} | ||
// swiftlint:enable file_length type_body_length line_length |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"status": true, | ||
"message": "Charge attempted", | ||
"data": { | ||
"transaction": "1504248187", | ||
"phone": "0703362111", | ||
"provider": "MPESA", | ||
"channel_name": "MOBILE_MONEY_1504248187", | ||
"display": { | ||
"type": "pop", | ||
"message": "Please complete authorization process on your mobile phone", | ||
"timer": 60 | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.