Skip to content

Commit

Permalink
Merge pull request #40 from moltin/feat/stripe-options
Browse files Browse the repository at this point in the history
Added options for Stripe tokens
  • Loading branch information
craigtweedy committed Dec 17, 2018
2 parents 422c15c + c0ee6cc commit 8c15587
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/SDK/Models/PaymentMethod.swift
Expand Up @@ -20,18 +20,28 @@ open class StripeToken: PaymentMethod {
/// The stripe token
var token: String

/// The stripe options
var options: [String: String]?

/// The payment data to be sent to the API
public var paymentData: [String: Any] {
return [
var payload: [String: Any] = [
"gateway": "stripe",
"method": "purchase",
"payment": self.token
]

if let options = self.options {
payload["options"] = options
}

return payload
}

/// Initialise the payment method with a stripe token
public init(withStripeToken token: String) {
public init(withStripeToken token: String, withOptions options: [String: String]? = nil) {
self.token = token
self.options = options
}
}

Expand Down
33 changes: 33 additions & 0 deletions Tests/moltin iOS Tests/PaymentMethodTests.swift
@@ -0,0 +1,33 @@
//
// PaymentMethodTests.swift
// moltin iOS Tests
//
// Created by Craig Tweedy on 16/12/2018.
//

import XCTest
import moltin

class PaymentMethodTests: XCTestCase {

func testStripeTokenPaymentMethodToken() {
let method = StripeToken(withStripeToken: "12345")
let paymentData = method.paymentData
XCTAssertEqual((paymentData["payment"] as? String), "12345")
}

func testStripeTokenPaymentMethodEmptyOptions() {
let method = StripeToken(withStripeToken: "12345")
let paymentData = method.paymentData
XCTAssertNil(paymentData["options"])
}

func testStripeTokenPaymentMethodWithOptions() {
let method = StripeToken(withStripeToken: "12345", withOptions: [
"destination": "6789"
])
let paymentData = method.paymentData
XCTAssertNotNil(paymentData["options"])
}

}
4 changes: 4 additions & 0 deletions moltin.xcodeproj/project.pbxproj
Expand Up @@ -56,6 +56,7 @@
C336E5D32064062E008C2005 /* Relationship.swift in Sources */ = {isa = PBXBuildFile; fileRef = C336E5CE2064057B008C2005 /* Relationship.swift */; };
C336E5F8206C0A18008C2005 /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C336E5F6206C0A12008C2005 /* MasterViewController.swift */; };
C336E608206C1E02008C2005 /* CategoryCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C336E604206C1DFD008C2005 /* CategoryCollectionViewCell.swift */; };
C339F42F21C6C309002C0A7A /* PaymentMethodTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C339F42E21C6C309002C0A7A /* PaymentMethodTests.swift */; };
C3434C0F203DDA0500883C84 /* MoltinRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3434C0E203DDA0500883C84 /* MoltinRequest.swift */; };
C3434C13203DDA1F00883C84 /* MoltinRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3434C0E203DDA0500883C84 /* MoltinRequest.swift */; };
C3434C18203DDAD500883C84 /* Pagination.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3434C17203DDAD500883C84 /* Pagination.swift */; };
Expand Down Expand Up @@ -254,6 +255,7 @@
C336E5F6206C0A12008C2005 /* MasterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = "<group>"; };
C336E604206C1DFD008C2005 /* CategoryCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCollectionViewCell.swift; sourceTree = "<group>"; };
C336E605206C1DFD008C2005 /* CategoryCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CategoryCollectionViewCell.xib; sourceTree = "<group>"; };
C339F42E21C6C309002C0A7A /* PaymentMethodTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentMethodTests.swift; sourceTree = "<group>"; };
C3434C0E203DDA0500883C84 /* MoltinRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoltinRequest.swift; sourceTree = "<group>"; };
C3434C17203DDAD500883C84 /* Pagination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pagination.swift; sourceTree = "<group>"; };
C3434C1C203DDAFF00883C84 /* Error.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -588,6 +590,7 @@
C3715BEE203F53A000287C1B /* AuthTests.swift */,
C3821AE220443C5F001EF864 /* CartTests.swift */,
C336E569206155BE008C2005 /* FlowTests.swift */,
C339F42E21C6C309002C0A7A /* PaymentMethodTests.swift */,
);
path = "moltin iOS Tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -1171,6 +1174,7 @@
C354B56D2073740200D26446 /* Collection.swift in Sources */,
C336E56E206155DF008C2005 /* FlowTests.swift in Sources */,
C354B5732073780000D26446 /* Field.swift in Sources */,
C339F42F21C6C309002C0A7A /* PaymentMethodTests.swift in Sources */,
C354B5752073791A00D26446 /* Cart.swift in Sources */,
C392EA15203DB7EB006CD1D0 /* MoltinTests.swift in Sources */,
C354B569206D1D0C00D26446 /* Brands.swift in Sources */,
Expand Down
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down

0 comments on commit 8c15587

Please sign in to comment.