Skip to content

Commit

Permalink
Merge pull request #47 from square/amberdixon/renameMerchantIDtoLocat…
Browse files Browse the repository at this point in the history
…ionID

Publishing API version 1.3: Rename merchant_id to location_id
  • Loading branch information
amberdixon authored Jun 15, 2017
2 parents 0782fd5 + de5c9f3 commit 7e4f9e6
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 140 deletions.
71 changes: 33 additions & 38 deletions HelloCharge-Swift/Base.lproj/HelloCharge-Swift.storyboard

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions HelloCharge-Swift/HelloChargeSwiftTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HelloChargeSwiftTableViewController: UITableViewController {

@IBOutlet weak var notesField: UITextField!
@IBOutlet weak var userInfoStringField: UITextField!
@IBOutlet weak var merchantIDField: UITextField!
@IBOutlet weak var locationIDField: UITextField!
@IBOutlet weak var customerIDField: UITextField!

override func awakeFromNib() {
Expand Down Expand Up @@ -132,7 +132,7 @@ class HelloChargeSwiftTableViewController: UITableViewController {
}

let userInfoString = userInfoStringField.text?.nilIfEmpty
let merchantID = merchantIDField.text?.nilIfEmpty
let locationID = locationIDField.text?.nilIfEmpty
let customerID = customerIDField.text?.nilIfEmpty
let notes = notesField.text?.nilIfEmpty

Expand All @@ -141,7 +141,7 @@ class HelloChargeSwiftTableViewController: UITableViewController {
request = try SCCAPIRequest(callbackURL: yourCallbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand Down
58 changes: 29 additions & 29 deletions HelloCharge/Base.lproj/HelloCharge.storyboard

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions HelloCharge/HelloChargeTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ @interface HelloChargeTableViewController ()

@property (weak, nonatomic) IBOutlet UITextField *userInfoStringField;
@property (weak, nonatomic) IBOutlet UITextField *notesField;
@property (weak, nonatomic) IBOutlet UITextField *merchantIDField;
@property (weak, nonatomic) IBOutlet UITextField *locationIDField;
@property (weak, nonatomic) IBOutlet UITextField *customerIDField;

- (IBAction)oauth:(id)sender;
Expand Down Expand Up @@ -134,14 +134,14 @@ - (IBAction)charge:(id)sender;
}

NSString *userInfoString = self.userInfoStringField.text.length ? self.userInfoStringField.text : nil;
NSString *merchantID = self.merchantIDField.text.length ? self.merchantIDField.text : nil;
NSString *locationID = self.locationIDField.text.length ? self.locationIDField.text : nil;
NSString *customerID = self.customerIDField.text.length ? self.customerIDField.text : nil;
NSString *notes = self.notesField.text.length ? self.notesField.text : nil;

SCCAPIRequest *request = [SCCAPIRequest requestWithCallbackURL:[NSURL URLWithString:yourCallbackURLString]
amount:amount
userInfoString:userInfoString
merchantID:merchantID
locationID:locationID
notes:notes
customerID:customerID
supportedTenderTypes:self.supportedTenderTypes
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- OCMock (3.3.1)
- SquarePointOfSaleSDK (3.0)
- SquarePointOfSaleSDK (3.1)

DEPENDENCIES:
- OCMock (~> 3.1)
Expand All @@ -12,7 +12,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
OCMock: f3f61e6eaa16038c30caa5798c5e49d3307b6f22
SquarePointOfSaleSDK: 4afc27f1ce296b6ae8654427d3fabb8bbd109f1e
SquarePointOfSaleSDK: b5f4d00022d88e31e20c81efeffa43f553128b9d

PODFILE CHECKSUM: 7600ae620186a2c36f24e003c307f483826f8c0b

Expand Down
13 changes: 13 additions & 0 deletions SquarePointOfSaleSDK Tests/NSError+SCCAPIAdditionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ class NSError_SCCAPIAdditionsTests: XCTestCase {
XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]);
}

func test_SCC_APIErrorWithErrorCodeString_locationIDError_backwardsCompatibility()
{
// Should return an appropriate error for a known error code string.
let errorCodeString = "location_id_mismatch"

let error = NSError.scc_APIErrorWithErrorCodeString(errorCodeString) as NSError
XCTAssertEqual(UInt(error.code), SCCAPIErrorCode.locationIDMismatch.rawValue)
//checking against deprecated value should work too for backwards compat
XCTAssertEqual(UInt(error.code), SCCAPIErrorCode.merchantIDMismatch.rawValue)
XCTAssertEqual(error.userInfo[SCCAPIErrorUserInfoCodeStringKey] as? String, errorCodeString)
XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]);
}

func test_SCC_APIErrorWithErrorCodeString_unknownError()
{
// For an unknown error string, should return an error with no code and the error string persisted.
Expand Down
4 changes: 2 additions & 2 deletions SquarePointOfSaleSDK Tests/SCCAPIConnectionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (void)test_canPerformRequestError_isYESWhenApplicationCanOpenURL;
SCCAPIRequest *const request = [SCCAPIRequest requestWithCallbackURL:callbackURL
amount:amount
userInfoString:nil
merchantID:nil
locationID:nil
notes:nil
customerID:nil
supportedTenderTypes:SCCAPIRequestTenderTypeCard
Expand Down Expand Up @@ -77,7 +77,7 @@ - (void)test_canPerformRequestError_isNOWhenApplicationCannotOpenURL;
SCCAPIRequest *const request = [SCCAPIRequest requestWithCallbackURL:callbackURL
amount:amount
userInfoString:nil
merchantID:nil
locationID:nil
notes:nil
customerID:nil
supportedTenderTypes:SCCAPIRequestTenderTypeCard
Expand Down
115 changes: 92 additions & 23 deletions SquarePointOfSaleSDK Tests/SCCAPIRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SCCAPIRequestTests: SCCTestCase {
func test_requestWithCallbackURL_propagatesAllParametersWhenValid() {
do {
let notes = "Notes"
let merchantID = "7074ME2C077ZB"
let locationID = "7074ME2C077ZB"
let customerID = "YT6ZX064G97X12NVED31CJJK34"
let userInfoString = "User Info"
let amount = try! SCCMoney(amountCents: 100, currencyCode: "USD")
Expand All @@ -61,7 +61,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -70,7 +70,7 @@ class SCCAPIRequestTests: SCCTestCase {

XCTAssertEqual(completeRequest.clientID, SCCAPIRequestTests.defaultTestClientID)
XCTAssertEqual(completeRequest.notes, notes)
XCTAssertEqual(completeRequest.merchantID, merchantID)
XCTAssertEqual(completeRequest.locationID, locationID)
XCTAssertEqual(completeRequest.customerID, customerID)
XCTAssertEqual(completeRequest.userInfoString, userInfoString)
XCTAssertEqual(completeRequest.amount, amount)
Expand All @@ -90,7 +90,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: URL(string: "register-sdk-testapp://myCallback")!,
amount: try! SCCMoney(amountCents: 100, currencyCode: "USD"),
userInfoString: nil,
merchantID: nil,
locationID: nil,
notes: nil,
customerID: nil,
supportedTenderTypes: SCCAPIRequestTenderTypes.all,
Expand All @@ -109,7 +109,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: URL(string: "//myCallback")!,
amount: try! SCCMoney(amountCents: 100, currencyCode: "USD"),
userInfoString: nil,
merchantID: nil,
locationID: nil,
notes: nil,
customerID: nil,
supportedTenderTypes: SCCAPIRequestTenderTypes.all,
Expand All @@ -128,7 +128,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: URL(string: "register-sdk-testapp://myCallback")!,
amount: try! SCCMoney(amountCents: -100, currencyCode: "USD"),
userInfoString: nil,
merchantID: nil,
locationID: nil,
notes: nil,
customerID: nil,
supportedTenderTypes: SCCAPIRequestTenderTypes.all,
Expand All @@ -147,7 +147,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: URL(string: "my-app://perform-callback")!,
amount: try! SCCMoney(amountCents: 100, currencyCode: "USD"),
userInfoString: "state-user-info",
merchantID: "abc123",
locationID: "abc123",
notes: "blue shoes",
customerID: "def456",
supportedTenderTypes: SCCAPIRequestTenderTypes.card,
Expand All @@ -157,15 +157,15 @@ class SCCAPIRequestTests: SCCTestCase {

let expectedData: [String : Any] = [
"client_id" : SCCAPIRequestTests.defaultTestClientID,
"sdk_version" : "3.0",
"version" : "1.2",
"sdk_version" : "3.1",
"version" : "1.3",
"amount_money" : [
"amount" : 100,
"currency_code" : "USD"
],
"callback_url" : "my-app://perform-callback",
"state" : "state-user-info",
"merchant_id" : "abc123",
"location_id" : "abc123",
"customer_id": "def456",
"notes" : "blue shoes",
"options" : [
Expand All @@ -183,7 +183,7 @@ class SCCAPIRequestTests: SCCTestCase {

func test_isEqualToAPIRequest_comparesAllFields() {
let notes = "Notes"
let merchantID = "7074ME2C077ZB"
let locationID = "7074ME2C077ZB"
let customerID = "YT6ZX064G97X12NVED31CJJK34"
let userInfoString = "User Info"
let amount = try! SCCMoney(amountCents: 100, currencyCode: "USD")
Expand All @@ -196,7 +196,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -208,7 +208,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -221,7 +221,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -234,7 +234,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: URL(string: "http://google.com")!,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -246,7 +246,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: try! SCCMoney(amountCents: 200, currencyCode: "USD"),
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -258,19 +258,19 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: "DIFFERENT_USER_INFO_STRING",
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
clearsDefaultFees: clearsDefaultFees,
returnAutomaticallyAfterPayment: autoreturn))

// Different merchant ID.
// Different location ID.
XCTAssertNotEqual(baseRequest, try! SCCAPIRequest(
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: "DIFFERENT_MERCHANT_ID",
locationID: "DIFFERENT_LOCATION_ID",
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -282,7 +282,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: "DIFFERENT_NOTES",
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -294,7 +294,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: "DIFFERENT_CUSTOMER_ID",
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -306,7 +306,7 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
Expand All @@ -318,14 +318,83 @@ class SCCAPIRequestTests: SCCTestCase {
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: merchantID,
locationID: locationID,
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
clearsDefaultFees: clearsDefaultFees,
returnAutomaticallyAfterPayment: !autoreturn))
}

func test_backwardsCompatibility_deprecatedMerchantID() {
let notes = "Notes"
let customerID = "YT6ZX064G97X12NVED31CJJK34"
let userInfoString = "User Info"
let amount = try! SCCMoney(amountCents: 100, currencyCode: "USD")
let callbackURL = URL(string: "register-sdk-testapp://myCallback")!
let supportedTenderTypes = SCCAPIRequestTenderTypes.card
let clearsDefaultFees = true
let autoreturn = true

let deprecatedRequest = try! SCCAPIRequest(
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
merchantID: "abc123",
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
clearsDefaultFees: clearsDefaultFees,
returnAutomaticallyAfterPayment: autoreturn)

// read back specified merchantID
XCTAssertEqual(deprecatedRequest.locationID, "abc123")
XCTAssertEqual(deprecatedRequest.merchantID, "abc123")

let anotherEqualRequest = try! SCCAPIRequest(
callbackURL: callbackURL,
amount: amount,
userInfoString: userInfoString,
locationID: "abc123",
notes: notes,
customerID: customerID,
supportedTenderTypes: supportedTenderTypes,
clearsDefaultFees: clearsDefaultFees,
returnAutomaticallyAfterPayment: autoreturn)
XCTAssertEqual(deprecatedRequest, anotherEqualRequest)

do {
// make sure it gets serialized correctly with location_id label
let requestURL = try deprecatedRequest.apiRequestURL()

let expectedData: [String : Any] = [
"client_id" : SCCAPIRequestTests.defaultTestClientID,
"sdk_version" : "3.1",
"version" : "1.3",
"amount_money" : [
"amount" : 100,
"currency_code" : "USD"
],
"callback_url" : "register-sdk-testapp://myCallback",
"state" : userInfoString,
"location_id" : "abc123",
"customer_id": customerID,
"notes" : notes,
"options" : [
"supported_tender_types" : [ "CREDIT_CARD" ],
"clear_default_fees" : clearsDefaultFees,
"auto_return" : autoreturn
]
]

XCTAssertEqual(NSDictionary(dictionary: expectedData), NSDictionary(dictionary: self.data(for: requestURL)));
} catch _ {
XCTFail()
}


}

func test_NSArrayOfTenderTypeStringsFromSCCAPIRequestTenderTypes_supportsAllTenderTypes() {
let noTenderTypes = SCCAPIRequestTenderTypes()
let noTenderStrings = NSArrayOfTenderTypeStringsFromSCCAPIRequestTenderTypes(noTenderTypes)
Expand Down
2 changes: 1 addition & 1 deletion SquarePointOfSaleSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SquarePointOfSaleSDK'
s.version = '3.0'
s.version = '3.1'
s.summary = 'SDK for easier use of Square\'s Point of Sale app-switching API on iOS'
s.homepage = 'https://github.com/square/SquarePointOfSaleSDK-iOS/'
s.license = { :type => 'Apache License, Version 2.0', :text => #{ Date.today.year } Square, Inc." }
Expand Down
3 changes: 2 additions & 1 deletion SquarePointOfSaleSDK/NSError+SCCAPIAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ typedef NS_ENUM(NSUInteger, SCCAPIErrorCode) {
SCCAPIErrorCodePayloadMissingOrInvalid,
SCCAPIErrorCodeAppNotLoggedIn,
SCCAPIErrorCodeUnused,
SCCAPIErrorCodeMerchantIDMismatch,
SCCAPIErrorCodeLocationIDMismatch,
SCCAPIErrorCodeMerchantIDMismatch __deprecated_enum_msg("Starting with Point of Sale API version 1.3, this error code has been replaced by SCCAPIErrorCodeLocationIDMismatch.") = SCCAPIErrorCodeLocationIDMismatch,
SCCAPIErrorCodeUserNotActivated,
SCCAPIErrorCodeCurrencyMissingOrInvalid,
SCCAPIErrorCodeCurrencyUnsupported,
Expand Down
Loading

0 comments on commit 7e4f9e6

Please sign in to comment.