Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Added support for eCheck in add PaymentMethod. #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Spreedly.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1AA1E632A293186FBB3A16C6 /* BankAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AA1E2FFD34847269F158BCF /* BankAccount.swift */; };
46FCEDAC26B28251A5441524 /* Pods_Spreedly.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24EB07D12C3865F11DBE8AE0 /* Pods_Spreedly.framework */; };
631723171BD67B81008EC5C2 /* Spreedly.h in Headers */ = {isa = PBXBuildFile; fileRef = 631723161BD67B81008EC5C2 /* Spreedly.h */; settings = {ATTRIBUTES = (Public, ); }; };
6337405A1BC967150091372A /* RequestSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 633740591BC967150091372A /* RequestSerializer.swift */; };
Expand Down Expand Up @@ -42,6 +43,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1AA1E2FFD34847269F158BCF /* BankAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BankAccount.swift; sourceTree = "<group>"; };
24EB07D12C3865F11DBE8AE0 /* Pods_Spreedly.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Spreedly.framework; sourceTree = BUILT_PRODUCTS_DIR; };
40DE46959D75210E93E40E58 /* Pods_Spreedly_SpreedlyTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Spreedly_SpreedlyTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4D261846DD7FC52334D6DC32 /* Pods-SpreedlyTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SpreedlyTests.release.xcconfig"; path = "Target Support Files/Pods-SpreedlyTests/Pods-SpreedlyTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -152,6 +154,7 @@
635843D81BD9269F006A4F6B /* PaymentMethod.swift */,
635843DA1BD9361F006A4F6B /* SpreedlyError.swift */,
63E67F801BC6C4600023E846 /* Supporting Files */,
1AA1E2FFD34847269F158BCF /* BankAccount.swift */,
);
path = Spreedly;
sourceTree = "<group>";
Expand Down Expand Up @@ -410,6 +413,7 @@
B2C26B27230DD80300FACDFD /* TransactionLifecycle.swift in Sources */,
63E67F7C1BC6C1420023E846 /* SpreedlyAPIClient.swift in Sources */,
635843DB1BD9361F006A4F6B /* SpreedlyError.swift in Sources */,
1AA1E632A293186FBB3A16C6 /* BankAccount.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 13 additions & 0 deletions Spreedly/BankAccount.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Created by Ray Harris on 4/25/18.
// Copyright (c) 2018 Spreedly Inc. All rights reserved.
//

import Foundation

open class BankAccount: NSObject {
open var firstName, lastName, routingNumber, accountNumber: String?
open var accountType, accountHolderType: String?

public override init() {}
}
13 changes: 12 additions & 1 deletion Spreedly/PaymentMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ open class PaymentMethod: NSObject {
open var shippingState, shippingZip, shippingCountry, shippingPhoneNumber: String?
open var verificationValue, number: String?
open var month, year: Int?

open var bankName, accountType, accountHolderType, routingNumberDisplayDigits, accountNumberDisplayDigits: String?

convenience init(attributes: [String: AnyObject]) {
self.init()

Expand Down Expand Up @@ -75,6 +76,16 @@ open class PaymentMethod: NSObject {
self.verificationValue = value as? String
case "number":
self.number = value as? String
case "bank_name":
self.bankName = value as? String
case "account_type":
self.accountType = value as? String
case "account_holder_type":
self.accountHolderType = value as? String
case "routing_number_display_digits":
self.routingNumberDisplayDigits = value as? String
case "account_number_display_digits":
self.accountNumberDisplayDigits = value as? String
default:
break;
}
Expand Down
37 changes: 37 additions & 0 deletions Spreedly/RequestSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,41 @@ open class RequestSerializer {
return (nil, serializeError)
}
}

open static func serialize(_ bankAccount: BankAccount) -> (data: Data?, error: NSError?) {
var dict = [String: String]()

if let bankAccountFirstName = bankAccount.firstName {
dict["first_name"] = bankAccountFirstName
}

if let bankAccountLastName = bankAccount.lastName {
dict["last_name"] = bankAccountLastName
}

if let bankAccountRoutingNumber = bankAccount.routingNumber {
dict["bank_routing_number"] = bankAccountRoutingNumber
}

if let bankAccountNumber = bankAccount.accountNumber {
dict["bank_account_number"] = bankAccountNumber
}

if let bankAccountType = bankAccount.accountType {
dict["bank_account_type"] = bankAccountType
}

if let bankAccountHolderType = bankAccount.accountHolderType {
dict["bank_account_holder_type"] = bankAccountHolderType
}

let body = [ "payment_method": [ "bank_account": dict ]]

do {
let data = try JSONSerialization.data(withJSONObject: body, options: [])
return (data, nil)
} catch let serializeError as NSError {
return (nil, serializeError)
}
}
}
10 changes: 10 additions & 0 deletions Spreedly/SpreedlyAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public class SpreedlyAPIClient: NSObject {
}
}
}

open func createPaymentMethodTokenWithBankAccount(_ bankAccount: BankAccount, completion: @escaping SpreedlyAPICompletionBlock) {
let serializedRequest = RequestSerializer.serialize(bankAccount)

if serializedRequest.error == nil {
if let data = serializedRequest.data {
self.createPaymentMethodTokenWithData(data, completion: completion)
}
}
}

public func createPaymentMethodTokenWithApplePay(_ payment: PKPayment, completion: @escaping tokenizeCompletion) {
self.createPaymentMethodTokenWithData(RequestSerializer.serialize(payment.token.paymentData), completion: completion)
Expand Down