Skip to content

Commit

Permalink
Merge pull request #928 from stripe/danj/feature/masterpass
Browse files Browse the repository at this point in the history
Add Masterpass to STPSourceParams, allowing Sources to be created
  • Loading branch information
danj-stripe authored Apr 17, 2018
2 parents 6124e0e + eb0f516 commit 6b5828b
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 16 additions & 0 deletions Stripe/PublicHeaders/STPSourceParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -298,6 +299,21 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (STPSourceParams *)visaCheckoutParamsWithCallId:(NSString *)callId;


/**
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
@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
15 changes: 15 additions & 0 deletions Stripe/STPSourceParams.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
56 changes: 56 additions & 0 deletions Tests/Tests/STPSourceFunctionalTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ @interface STPSourceFunctionalTest : XCTestCase

@end

@interface STPAPIClient (WritableURL)
@property (nonatomic, readwrite) NSURL *apiURL;
@end

@implementation STPSourceFunctionalTest

- (void)testCreateSource_bancontact {
Expand Down Expand Up @@ -295,6 +299,58 @@ - (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
// 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"
Expand Down
24 changes: 24 additions & 0 deletions Tests/Tests/STPSourceParamsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,30 @@ - (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"];

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

Expand Down

0 comments on commit 6b5828b

Please sign in to comment.