Skip to content

Commit

Permalink
Merge pull request #81 from pokepay/credit-card-api
Browse files Browse the repository at this point in the history
Credit card api
  • Loading branch information
ZweWaiYanHtet authored Jul 30, 2024
2 parents df67ba5 + 819276f commit c87fe56
Show file tree
Hide file tree
Showing 21 changed files with 469 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"repositoryURL": "https://github.com/ishkawa/APIKit",
"state": {
"branch": null,
"revision": "86d51ecee0bc0ebdb53fb69b11a24169a69097ba",
"version": "4.1.0"
"revision": "b839e53b870104798035b279d2a6168b0a2227b1",
"version": "5.4.0"
}
},
{
"package": "Result",
"repositoryURL": "https://github.com/antitypical/Result.git",
"state": {
"branch": null,
"revision": "2ca499ba456795616fbc471561ff1d963e6ae160",
"version": "4.1.0"
"revision": "12920a5c2595926efab9274d6003e29f503dbb66",
"version": "5.0.0"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/ishkawa/APIKit", from: "4.0.0"),
.package(url: "https://github.com/antitypical/Result.git", from: "4.0.0"),
.package(url: "https://github.com/ishkawa/APIKit", from: "5.0.0"),
.package(url: "https://github.com/antitypical/Result.git", from: "5.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
2 changes: 1 addition & 1 deletion Pokepay.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Pokepay"
s.version = "2.0.13"
s.version = "2.0.15"
s.summary = "Pokepay iOS SDK."
s.description = <<-DESC
iOS SDK for Pokepay written in Swift.
Expand Down
2 changes: 1 addition & 1 deletion Pokepay.xcodeproj/Pokepay_Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.0.13</string>
<string>2.0.15</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
5 changes: 4 additions & 1 deletion Sources/Pokepay/BankAPI.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// DO NOT EDIT: File is generated by code generator.

public struct BankAPI {
public struct Account {}
public struct Bill {}
public struct Cashtray {}
public struct Check {}
public struct CpmToken {}
public struct CreditCard {}
public struct PrivateMoney {}
public struct Terminal {}
public struct Transaction {}
public struct User {}
public struct PrivateMoney {}
}
25 changes: 23 additions & 2 deletions Sources/Pokepay/BankAPI/BankAPIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import APIKit
let DEFAULT_API_BASE_URL = "https://api-sandbox.pokepay.jp"

public protocol BankRequest: Request {
var responseContentType: String { get }
}

public extension BankRequest {
var baseURL: URL {
return URL(string: DEFAULT_API_BASE_URL)!
}

var responseContentType: String {
return "application/json"
}
}

public extension BankRequest {
Expand All @@ -23,17 +28,33 @@ public extension BankRequest {

extension BankRequest where Response: Decodable {
public var dataParser: DataParser {
return DecodableDataParser()
switch responseContentType {
case "text/html":
return HTMLDataParser()
default:
return DecodableDataParser()
}
}

public func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response {
guard let data = object as? Data else {
throw BankAPIError(statusCode: urlResponse.statusCode, object: Data())
}

guard data.count != 0 else {
let emptyJson = "{}"
return try BankAPIJSONDecoder().decode(Response.self, from: emptyJson.data(using: .utf8)!)
}
return try BankAPIJSONDecoder().decode(Response.self, from: data)

switch responseContentType {
case "text/html":
if let htmlString = String(data: data, encoding: .utf8) as? Response {
return htmlString
} else {
throw BankAPIError(statusCode: urlResponse.statusCode, object: data)
}
default:
return try BankAPIJSONDecoder().decode(Response.self, from: data)
}
}
}
44 changes: 44 additions & 0 deletions Sources/Pokepay/BankAPI/CreditCard/CreateCreditCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// DO NOT EDIT: File is generated by code generator.
import APIKit

public extension BankAPI.CreditCard {
struct CreateCreditCard: BankRequest {
public let token: String
public let isCardholderNameSpecified: Bool?
public let organizationCode: String?
public let userId: String

public typealias Response = CreditCard

public init(token: String, isCardholderNameSpecified: Bool? = nil, organizationCode: String? = nil, userId: String) {
self.token = token
self.isCardholderNameSpecified = isCardholderNameSpecified
self.organizationCode = organizationCode
self.userId = userId
}

public var method: HTTPMethod {
return .post
}

public var path: String {
return "/users/\(userId)/cards"
}

public var parameters: Any? {
var dict: [String: Any] = [:]

dict["token"] = token

if isCardholderNameSpecified != nil {
dict["is_cardholder_name_specified"] = isCardholderNameSpecified
}

if organizationCode != nil {
dict["organization_code"] = organizationCode
}

return dict
}
}
}
38 changes: 38 additions & 0 deletions Sources/Pokepay/BankAPI/CreditCard/DeleteCreditCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// DO NOT EDIT: File is generated by code generator.
import APIKit

public extension BankAPI.CreditCard {
struct DeleteCreditCard: BankRequest {
public let cardRegisteredAt: String
public let organizationCode: String?
public let userId: String

public typealias Response = NoContent

public init(cardRegisteredAt: String, organizationCode: String? = nil, userId: String) {
self.cardRegisteredAt = cardRegisteredAt
self.organizationCode = organizationCode
self.userId = userId
}

public var method: HTTPMethod {
return .post
}

public var path: String {
return "/users/\(userId)/cards/delete"
}

public var parameters: Any? {
var dict: [String: Any] = [:]

dict["card_registered_at"] = cardRegisteredAt

if organizationCode != nil {
dict["organization_code"] = organizationCode
}

return dict
}
}
}
52 changes: 52 additions & 0 deletions Sources/Pokepay/BankAPI/CreditCard/GetCreditCards.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// DO NOT EDIT: File is generated by code generator.
import APIKit

public extension BankAPI.CreditCard {
struct GetCreditCards: BankRequest {
public let userId: String
public let before: String?
public let after: String?
public let perPage: Int?
public let organizationCode: String?

public typealias Response = PaginatedCreditCards

public init(userId: String, before: String? = nil, after: String? = nil, perPage: Int? = nil, organizationCode: String? = nil) {
self.userId = userId
self.before = before
self.after = after
self.perPage = perPage
self.organizationCode = organizationCode
}

public var method: HTTPMethod {
return .get
}

public var path: String {
return "/users/\(userId)/cards"
}

public var parameters: Any? {
var dict: [String: Any] = [:]

if before != nil {
dict["before"] = before
}

if after != nil {
dict["after"] = after
}

if perPage != nil {
dict["per_page"] = perPage
}

if organizationCode != nil {
dict["organization_code"] = organizationCode
}

return dict
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// DO NOT EDIT: File is generated by code generator.
import APIKit

public extension BankAPI.CreditCard {
struct TopupWithCreditCardMdkToken: BankRequest {
public let userId: String
public let token: String
public let accountId: String
public let amount: Int
public let organizationCode: String?
public let isCardholderNameSpecified: Bool?

public typealias Response = String

public init(userId: String, token: String, accountId: String, amount: Int, organizationCode: String? = nil, isCardholderNameSpecified: Bool? = nil) {
self.userId = userId
self.token = token
self.accountId = accountId
self.amount = amount
self.organizationCode = organizationCode
self.isCardholderNameSpecified = isCardholderNameSpecified
}

public var method: HTTPMethod {
return .post
}

public var path: String {
return "/veritrans/card-authorize/topup-with-mdk-token"
}

public var parameters: Any? {
var dict: [String: Any] = [:]

dict["user_id"] = userId

dict["token"] = token

dict["account_id"] = accountId

dict["amount"] = amount

if organizationCode != nil {
dict["organization_code"] = organizationCode
}

if isCardholderNameSpecified != nil {
dict["is_cardholder_name_specified"] = isCardholderNameSpecified
}

return dict
}

public var responseContentType: String {
return "text/html"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// DO NOT EDIT: File is generated by code generator.
import APIKit

public extension BankAPI.CreditCard {
struct TopupWithCreditCardMembership: BankRequest {
public let userId: String
public let cardRegisteredAt: String
public let accountId: String
public let amount: Int
public let deleteCardIfAuthFail: Bool?
public let organizationCode: String?

public typealias Response = String

public init(userId: String, cardRegisteredAt: String, accountId: String, amount: Int, deleteCardIfAuthFail: Bool? = nil, organizationCode: String? = nil) {
self.userId = userId
self.cardRegisteredAt = cardRegisteredAt
self.accountId = accountId
self.amount = amount
self.deleteCardIfAuthFail = deleteCardIfAuthFail
self.organizationCode = organizationCode
}

public var method: HTTPMethod {
return .post
}

public var path: String {
return "/veritrans/card-authorize/topup-with-membership"
}

public var parameters: Any? {
var dict: [String: Any] = [:]

dict["user_id"] = userId

dict["card_registered_at"] = cardRegisteredAt

dict["account_id"] = accountId

dict["amount"] = amount

if deleteCardIfAuthFail != nil {
dict["delete_card_if_auth_fail"] = deleteCardIfAuthFail
}

if organizationCode != nil {
dict["organization_code"] = organizationCode
}

return dict
}

public var responseContentType: String {
return "text/html"
}
}
}
12 changes: 12 additions & 0 deletions Sources/Pokepay/HTMLDataParser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation
import APIKit

final class HTMLDataParser: DataParser {
var contentType: String? {
return "text/html"
}

func parse(data: Data) throws -> Any {
return data
}
}
Loading

0 comments on commit c87fe56

Please sign in to comment.