From ee6a6adc09d9830201d5feff28db4131e0d5026f Mon Sep 17 00:00:00 2001 From: Brian Dorfman Date: Tue, 12 Dec 2017 13:34:21 -0800 Subject: [PATCH 1/6] Add Masterpass support to STPSourceParams, creating Sources from cart & transaction ID --- Stripe/PublicHeaders/STPSourceParams.h | 14 ++++++++++++++ Stripe/STPSourceParams.m | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Stripe/PublicHeaders/STPSourceParams.h b/Stripe/PublicHeaders/STPSourceParams.h index ebacb068daa..def276980ec 100644 --- a/Stripe/PublicHeaders/STPSourceParams.h +++ b/Stripe/PublicHeaders/STPSourceParams.h @@ -298,6 +298,20 @@ NS_ASSUME_NONNULL_BEGIN */ + (STPSourceParams *)visaCheckoutParamsWithCallId:(NSString *)callId; + +/** + Creates params for a card source created from Masterpass. + + @note Creating an STPSource with these params will give you a + source with type == STPSourceTypeCard + + @param cartId The cartId from a `MCCCheckoutResponse` object. + @param transactionId The transactionid from a `MCCCheckoutResponse` object. + @return An STPSourceParams object populated with the provided values. + */ ++ (STPSourceParams *)masterpassParamsWithCartId:(NSString *)cartId + transactionId:(NSString *)transactionId; + @end NS_ASSUME_NONNULL_END diff --git a/Stripe/STPSourceParams.m b/Stripe/STPSourceParams.m index 81c662084cb..7c291f1c8e0 100644 --- a/Stripe/STPSourceParams.m +++ b/Stripe/STPSourceParams.m @@ -308,6 +308,21 @@ + (STPSourceParams *)visaCheckoutParamsWithCallId:(NSString *)callId { return params; } ++ (STPSourceParams *)masterpassParamsWithCartId:(NSString *)cartId + transactionId:(NSString *)transactionId { + STPSourceParams *params = [self new]; + params.type = STPSourceTypeCard; + params.additionalAPIParameters = @{ @"card": @{ + @"masterpass": @{ + @"cart_id": cartId, + @"transaction_id": transactionId, + } + } + + }; + return params; +} + #pragma mark - Redirect Dictionary /** From 6dffcf75835241f9389d8912ea8d360658b55021 Mon Sep 17 00:00:00 2001 From: Dan Jackson Date: Tue, 17 Apr 2018 14:23:58 -0700 Subject: [PATCH 2/6] Add hardcoded test for Masterpass - provide your own cart & transaction id and publishable key These are not re-usable, so you need to provide new values every time the test is run. I wish I had a better testing story here, but this is what we've come up with so far. --- Tests/Tests/STPSourceFunctionalTest.m | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Tests/Tests/STPSourceFunctionalTest.m b/Tests/Tests/STPSourceFunctionalTest.m index 21c347aa3b6..188d9546b2f 100644 --- a/Tests/Tests/STPSourceFunctionalTest.m +++ b/Tests/Tests/STPSourceFunctionalTest.m @@ -16,6 +16,10 @@ @interface STPSourceFunctionalTest : XCTestCase @end +@interface STPAPIClient (WritableURL) +@property (nonatomic, readwrite) NSURL *apiURL; +@end + @implementation STPSourceFunctionalTest - (void)testCreateSource_bancontact { @@ -295,6 +299,32 @@ - (void)testCreateSource_threeDSecure { [self waitForExpectationsWithTimeout:5.0f handler:nil]; } +- (void)skip_testCreateSourceMasterpass { + // The SDK does not have a means of generating Masterpass params for testing. Supply your own + // cartId & transactionId, and the correct publishable key, and you can run this test case + // manually after removing the `skip_` prefix. It'll log the source's stripeID, and that + // can be verified in dashboard. + STPSourceParams *params = [STPSourceParams masterpassParamsWithCartId:@"" transactionId:@""]; + STPAPIClient *client = [[STPAPIClient alloc] initWithPublishableKey:@"pk_"]; + client.apiURL = [NSURL URLWithString:@"https://api.stripe.com/v1"]; + + XCTestExpectation *sourceExp = [self expectationWithDescription:@"Masterpass source created"]; + [client createSourceWithParams:params completion:^(STPSource * _Nullable source, NSError * _Nullable error) { + [sourceExp fulfill]; + + XCTAssertNil(error); + XCTAssertNotNil(source); + XCTAssertEqual(source.type, STPSourceTypeCard); + XCTAssertEqual(source.flow, STPSourceFlowNone); + XCTAssertEqual(source.status, STPSourceStatusChargeable); + XCTAssertEqual(source.usage, STPSourceUsageSingleUse); + XCTAssertTrue([source.stripeID hasPrefix:@"src_"]); + NSLog(@"Created a Masterpass source %@", source.stripeID); + }]; + + [self waitForExpectationsWithTimeout:10.0 handler:nil]; +} + - (void)testCreateSource_alipay { STPSourceParams *params = [STPSourceParams alipayParamsWithAmount:1099 currency:@"usd" From dd3f3da3ec014f41b67dde27be57a2e7fe8c55b3 Mon Sep 17 00:00:00 2001 From: Dan Jackson Date: Tue, 17 Apr 2018 14:32:38 -0700 Subject: [PATCH 3/6] Add basic STPSourceParams unit test for masterpass api parameters --- Tests/Tests/STPSourceParamsTest.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/Tests/STPSourceParamsTest.m b/Tests/Tests/STPSourceParamsTest.m index c3db45a3281..4a64ad6e569 100644 --- a/Tests/Tests/STPSourceParamsTest.m +++ b/Tests/Tests/STPSourceParamsTest.m @@ -203,6 +203,19 @@ - (void)testCardParamsWithCard { XCTAssertEqualObjects(sourceAddress[@"country"], card.address.country); } +- (void)testParamsWithMasterPass { + STPSourceParams *params = [STPSourceParams masterpassParamsWithCartId:@"12345678" + transactionId:@"87654321"]; + + XCTAssertEqual(params.type, STPSourceTypeCard); + NSDictionary *sourceCard = params.additionalAPIParameters[@"card"]; + XCTAssertNotNil(sourceCard); + NSDictionary *sourceMasterpass = sourceCard[@"masterpass"]; + XCTAssertNotNil(sourceMasterpass); + XCTAssertEqualObjects(sourceMasterpass[@"cart_id"], @"12345678"); + XCTAssertEqualObjects(sourceMasterpass[@"transaction_id"], @"87654321"); +} + #pragma mark - Redirect Dictionary Tests From 4a8198c089a4e3d8988224cd0d768146dc841517 Mon Sep 17 00:00:00 2001 From: Dan Jackson Date: Tue, 17 Apr 2018 14:38:21 -0700 Subject: [PATCH 4/6] Add tests for Visa Checkout that match the minimal tests for masterpass This moves the hardcoded test for VCO out of a private branch I had, and at least puts it into master, even if it's disabled. The other test basically just ensures that dictionaries work correctly, but it'll also hopefully help guard against unintentionally breaking the format of the payload. --- Tests/Tests/STPSourceFunctionalTest.m | 26 ++++++++++++++++++++++++++ Tests/Tests/STPSourceParamsTest.m | 11 +++++++++++ 2 files changed, 37 insertions(+) diff --git a/Tests/Tests/STPSourceFunctionalTest.m b/Tests/Tests/STPSourceFunctionalTest.m index 188d9546b2f..0e93db41afb 100644 --- a/Tests/Tests/STPSourceFunctionalTest.m +++ b/Tests/Tests/STPSourceFunctionalTest.m @@ -299,6 +299,32 @@ - (void)testCreateSource_threeDSecure { [self waitForExpectationsWithTimeout:5.0f handler:nil]; } +- (void)skip_testCreateSourceVisaCheckout { + // The SDK does not have a means of generating Visa Checkout params for testing. Supply your own + // callId, and the correct publishable key, and you can run this test case + // manually after removing the `skip_` prefix. It'll log the source's stripeID, and that + // can be verified in dashboard. + STPSourceParams *params = [STPSourceParams visaCheckoutParamsWithCallId:@""]; + STPAPIClient *client = [[STPAPIClient alloc] initWithPublishableKey:@"pk_"]; + client.apiURL = [NSURL URLWithString:@"https://api.stripe.com/v1"]; + + XCTestExpectation *sourceExp = [self expectationWithDescription:@"VCO source created"]; + [client createSourceWithParams:params completion:^(STPSource * _Nullable source, NSError * _Nullable error) { + [sourceExp fulfill]; + + XCTAssertNil(error); + XCTAssertNotNil(source); + XCTAssertEqual(source.type, STPSourceTypeCard); + XCTAssertEqual(source.flow, STPSourceFlowNone); + XCTAssertEqual(source.status, STPSourceStatusChargeable); + XCTAssertEqual(source.usage, STPSourceUsageReusable); + XCTAssertTrue([source.stripeID hasPrefix:@"src_"]); + NSLog(@"Created a VCO source %@", source.stripeID); + }]; + + [self waitForExpectationsWithTimeout:10.0 handler:nil]; +} + - (void)skip_testCreateSourceMasterpass { // The SDK does not have a means of generating Masterpass params for testing. Supply your own // cartId & transactionId, and the correct publishable key, and you can run this test case diff --git a/Tests/Tests/STPSourceParamsTest.m b/Tests/Tests/STPSourceParamsTest.m index 4a64ad6e569..73c8008e44a 100644 --- a/Tests/Tests/STPSourceParamsTest.m +++ b/Tests/Tests/STPSourceParamsTest.m @@ -203,6 +203,17 @@ - (void)testCardParamsWithCard { XCTAssertEqualObjects(sourceAddress[@"country"], card.address.country); } +- (void)testParamsWithVisaCheckout { + STPSourceParams *params = [STPSourceParams visaCheckoutParamsWithCallId:@"12345678"]; + + XCTAssertEqual(params.type, STPSourceTypeCard); + NSDictionary *sourceCard = params.additionalAPIParameters[@"card"]; + XCTAssertNotNil(sourceCard); + NSDictionary *sourceVisaCheckout = sourceCard[@"visa_checkout"]; + XCTAssertNotNil(sourceVisaCheckout); + XCTAssertEqualObjects(sourceVisaCheckout[@"callid"], @"12345678"); +} + - (void)testParamsWithMasterPass { STPSourceParams *params = [STPSourceParams masterpassParamsWithCartId:@"12345678" transactionId:@"87654321"]; From 52c25a3f65fd7d2718b27020079ce21c6ece68c6 Mon Sep 17 00:00:00 2001 From: Dan Jackson Date: Tue, 17 Apr 2018 14:45:03 -0700 Subject: [PATCH 5/6] Add link to docs, even though they are not fully live yet --- Stripe/PublicHeaders/STPSourceParams.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Stripe/PublicHeaders/STPSourceParams.h b/Stripe/PublicHeaders/STPSourceParams.h index def276980ec..351d10ce267 100644 --- a/Stripe/PublicHeaders/STPSourceParams.h +++ b/Stripe/PublicHeaders/STPSourceParams.h @@ -289,6 +289,7 @@ NS_ASSUME_NONNULL_BEGIN /** Creates params for a card source created from Visa Checkout. + @see https://stripe.com/docs/visa-checkout @note Creating an STPSource with these params will give you a source with type == STPSourceTypeCard @@ -301,6 +302,7 @@ NS_ASSUME_NONNULL_BEGIN /** Creates params for a card source created from Masterpass. + @see https://stripe.com/docs/masterpass @note Creating an STPSource with these params will give you a source with type == STPSourceTypeCard From eb0f5160ab0f5f2d9b6d2a0943da1d782419dace Mon Sep 17 00:00:00 2001 From: Dan Jackson Date: Tue, 17 Apr 2018 15:09:59 -0700 Subject: [PATCH 6/6] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3adced922c6..941e1421f4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Adding Masterpass support to `STPSourceParams` [#928](https://github.com/stripe/stripe-ios/pull/928) * Silence STPAddress deprecation warnings we ignore to stay compatible with older iOS versions * Fix "Card IO" link in full SDK reference https://github.com/stripe/stripe-ios/pull/913