Skip to content

Commit c87fe56

Browse files
Merge pull request #81 from pokepay/credit-card-api
Credit card api
2 parents df67ba5 + 819276f commit c87fe56

21 files changed

+469
-11
lines changed

Package.resolved

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"repositoryURL": "https://github.com/ishkawa/APIKit",
77
"state": {
88
"branch": null,
9-
"revision": "86d51ecee0bc0ebdb53fb69b11a24169a69097ba",
10-
"version": "4.1.0"
9+
"revision": "b839e53b870104798035b279d2a6168b0a2227b1",
10+
"version": "5.4.0"
1111
}
1212
},
1313
{
1414
"package": "Result",
1515
"repositoryURL": "https://github.com/antitypical/Result.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "2ca499ba456795616fbc471561ff1d963e6ae160",
19-
"version": "4.1.0"
18+
"revision": "12920a5c2595926efab9274d6003e29f503dbb66",
19+
"version": "5.0.0"
2020
}
2121
}
2222
]

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ let package = Package(
1313
],
1414
dependencies: [
1515
// Dependencies declare other packages that this package depends on.
16-
.package(url: "https://github.com/ishkawa/APIKit", from: "4.0.0"),
17-
.package(url: "https://github.com/antitypical/Result.git", from: "4.0.0"),
16+
.package(url: "https://github.com/ishkawa/APIKit", from: "5.0.0"),
17+
.package(url: "https://github.com/antitypical/Result.git", from: "5.0.0"),
1818
],
1919
targets: [
2020
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

Pokepay.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Pokepay"
3-
s.version = "2.0.13"
3+
s.version = "2.0.15"
44
s.summary = "Pokepay iOS SDK."
55
s.description = <<-DESC
66
iOS SDK for Pokepay written in Swift.

Pokepay.xcodeproj/Pokepay_Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.0.13</string>
18+
<string>2.0.15</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Sources/Pokepay/BankAPI.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
// DO NOT EDIT: File is generated by code generator.
2+
13
public struct BankAPI {
24
public struct Account {}
35
public struct Bill {}
46
public struct Cashtray {}
57
public struct Check {}
68
public struct CpmToken {}
9+
public struct CreditCard {}
10+
public struct PrivateMoney {}
711
public struct Terminal {}
812
public struct Transaction {}
913
public struct User {}
10-
public struct PrivateMoney {}
1114
}

Sources/Pokepay/BankAPI/BankAPIRequest.swift

+23-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import APIKit
44
let DEFAULT_API_BASE_URL = "https://api-sandbox.pokepay.jp"
55

66
public protocol BankRequest: Request {
7+
var responseContentType: String { get }
78
}
89

910
public extension BankRequest {
1011
var baseURL: URL {
1112
return URL(string: DEFAULT_API_BASE_URL)!
1213
}
14+
15+
var responseContentType: String {
16+
return "application/json"
17+
}
1318
}
1419

1520
public extension BankRequest {
@@ -23,17 +28,33 @@ public extension BankRequest {
2328

2429
extension BankRequest where Response: Decodable {
2530
public var dataParser: DataParser {
26-
return DecodableDataParser()
31+
switch responseContentType {
32+
case "text/html":
33+
return HTMLDataParser()
34+
default:
35+
return DecodableDataParser()
36+
}
2737
}
2838

2939
public func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response {
3040
guard let data = object as? Data else {
3141
throw BankAPIError(statusCode: urlResponse.statusCode, object: Data())
3242
}
43+
3344
guard data.count != 0 else {
3445
let emptyJson = "{}"
3546
return try BankAPIJSONDecoder().decode(Response.self, from: emptyJson.data(using: .utf8)!)
3647
}
37-
return try BankAPIJSONDecoder().decode(Response.self, from: data)
48+
49+
switch responseContentType {
50+
case "text/html":
51+
if let htmlString = String(data: data, encoding: .utf8) as? Response {
52+
return htmlString
53+
} else {
54+
throw BankAPIError(statusCode: urlResponse.statusCode, object: data)
55+
}
56+
default:
57+
return try BankAPIJSONDecoder().decode(Response.self, from: data)
58+
}
3859
}
3960
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// DO NOT EDIT: File is generated by code generator.
2+
import APIKit
3+
4+
public extension BankAPI.CreditCard {
5+
struct CreateCreditCard: BankRequest {
6+
public let token: String
7+
public let isCardholderNameSpecified: Bool?
8+
public let organizationCode: String?
9+
public let userId: String
10+
11+
public typealias Response = CreditCard
12+
13+
public init(token: String, isCardholderNameSpecified: Bool? = nil, organizationCode: String? = nil, userId: String) {
14+
self.token = token
15+
self.isCardholderNameSpecified = isCardholderNameSpecified
16+
self.organizationCode = organizationCode
17+
self.userId = userId
18+
}
19+
20+
public var method: HTTPMethod {
21+
return .post
22+
}
23+
24+
public var path: String {
25+
return "/users/\(userId)/cards"
26+
}
27+
28+
public var parameters: Any? {
29+
var dict: [String: Any] = [:]
30+
31+
dict["token"] = token
32+
33+
if isCardholderNameSpecified != nil {
34+
dict["is_cardholder_name_specified"] = isCardholderNameSpecified
35+
}
36+
37+
if organizationCode != nil {
38+
dict["organization_code"] = organizationCode
39+
}
40+
41+
return dict
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// DO NOT EDIT: File is generated by code generator.
2+
import APIKit
3+
4+
public extension BankAPI.CreditCard {
5+
struct DeleteCreditCard: BankRequest {
6+
public let cardRegisteredAt: String
7+
public let organizationCode: String?
8+
public let userId: String
9+
10+
public typealias Response = NoContent
11+
12+
public init(cardRegisteredAt: String, organizationCode: String? = nil, userId: String) {
13+
self.cardRegisteredAt = cardRegisteredAt
14+
self.organizationCode = organizationCode
15+
self.userId = userId
16+
}
17+
18+
public var method: HTTPMethod {
19+
return .post
20+
}
21+
22+
public var path: String {
23+
return "/users/\(userId)/cards/delete"
24+
}
25+
26+
public var parameters: Any? {
27+
var dict: [String: Any] = [:]
28+
29+
dict["card_registered_at"] = cardRegisteredAt
30+
31+
if organizationCode != nil {
32+
dict["organization_code"] = organizationCode
33+
}
34+
35+
return dict
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// DO NOT EDIT: File is generated by code generator.
2+
import APIKit
3+
4+
public extension BankAPI.CreditCard {
5+
struct GetCreditCards: BankRequest {
6+
public let userId: String
7+
public let before: String?
8+
public let after: String?
9+
public let perPage: Int?
10+
public let organizationCode: String?
11+
12+
public typealias Response = PaginatedCreditCards
13+
14+
public init(userId: String, before: String? = nil, after: String? = nil, perPage: Int? = nil, organizationCode: String? = nil) {
15+
self.userId = userId
16+
self.before = before
17+
self.after = after
18+
self.perPage = perPage
19+
self.organizationCode = organizationCode
20+
}
21+
22+
public var method: HTTPMethod {
23+
return .get
24+
}
25+
26+
public var path: String {
27+
return "/users/\(userId)/cards"
28+
}
29+
30+
public var parameters: Any? {
31+
var dict: [String: Any] = [:]
32+
33+
if before != nil {
34+
dict["before"] = before
35+
}
36+
37+
if after != nil {
38+
dict["after"] = after
39+
}
40+
41+
if perPage != nil {
42+
dict["per_page"] = perPage
43+
}
44+
45+
if organizationCode != nil {
46+
dict["organization_code"] = organizationCode
47+
}
48+
49+
return dict
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// DO NOT EDIT: File is generated by code generator.
2+
import APIKit
3+
4+
public extension BankAPI.CreditCard {
5+
struct TopupWithCreditCardMdkToken: BankRequest {
6+
public let userId: String
7+
public let token: String
8+
public let accountId: String
9+
public let amount: Int
10+
public let organizationCode: String?
11+
public let isCardholderNameSpecified: Bool?
12+
13+
public typealias Response = String
14+
15+
public init(userId: String, token: String, accountId: String, amount: Int, organizationCode: String? = nil, isCardholderNameSpecified: Bool? = nil) {
16+
self.userId = userId
17+
self.token = token
18+
self.accountId = accountId
19+
self.amount = amount
20+
self.organizationCode = organizationCode
21+
self.isCardholderNameSpecified = isCardholderNameSpecified
22+
}
23+
24+
public var method: HTTPMethod {
25+
return .post
26+
}
27+
28+
public var path: String {
29+
return "/veritrans/card-authorize/topup-with-mdk-token"
30+
}
31+
32+
public var parameters: Any? {
33+
var dict: [String: Any] = [:]
34+
35+
dict["user_id"] = userId
36+
37+
dict["token"] = token
38+
39+
dict["account_id"] = accountId
40+
41+
dict["amount"] = amount
42+
43+
if organizationCode != nil {
44+
dict["organization_code"] = organizationCode
45+
}
46+
47+
if isCardholderNameSpecified != nil {
48+
dict["is_cardholder_name_specified"] = isCardholderNameSpecified
49+
}
50+
51+
return dict
52+
}
53+
54+
public var responseContentType: String {
55+
return "text/html"
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// DO NOT EDIT: File is generated by code generator.
2+
import APIKit
3+
4+
public extension BankAPI.CreditCard {
5+
struct TopupWithCreditCardMembership: BankRequest {
6+
public let userId: String
7+
public let cardRegisteredAt: String
8+
public let accountId: String
9+
public let amount: Int
10+
public let deleteCardIfAuthFail: Bool?
11+
public let organizationCode: String?
12+
13+
public typealias Response = String
14+
15+
public init(userId: String, cardRegisteredAt: String, accountId: String, amount: Int, deleteCardIfAuthFail: Bool? = nil, organizationCode: String? = nil) {
16+
self.userId = userId
17+
self.cardRegisteredAt = cardRegisteredAt
18+
self.accountId = accountId
19+
self.amount = amount
20+
self.deleteCardIfAuthFail = deleteCardIfAuthFail
21+
self.organizationCode = organizationCode
22+
}
23+
24+
public var method: HTTPMethod {
25+
return .post
26+
}
27+
28+
public var path: String {
29+
return "/veritrans/card-authorize/topup-with-membership"
30+
}
31+
32+
public var parameters: Any? {
33+
var dict: [String: Any] = [:]
34+
35+
dict["user_id"] = userId
36+
37+
dict["card_registered_at"] = cardRegisteredAt
38+
39+
dict["account_id"] = accountId
40+
41+
dict["amount"] = amount
42+
43+
if deleteCardIfAuthFail != nil {
44+
dict["delete_card_if_auth_fail"] = deleteCardIfAuthFail
45+
}
46+
47+
if organizationCode != nil {
48+
dict["organization_code"] = organizationCode
49+
}
50+
51+
return dict
52+
}
53+
54+
public var responseContentType: String {
55+
return "text/html"
56+
}
57+
}
58+
}

Sources/Pokepay/HTMLDataParser.swift

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Foundation
2+
import APIKit
3+
4+
final class HTMLDataParser: DataParser {
5+
var contentType: String? {
6+
return "text/html"
7+
}
8+
9+
func parse(data: Data) throws -> Any {
10+
return data
11+
}
12+
}

0 commit comments

Comments
 (0)