Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helpers for EPS and Multibanco source creation #961

Merged
merged 2 commits into from
Jun 8, 2018
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Fixes payment method label overlapping the checkmark, for Amex on small devices [#952](https://github.com/stripe/stripe-ios/pull/952)
* Adds EPS and Multibanco support to `STPSourceParams` [#961](https://github.com/stripe/stripe-ios/pull/961)

## 13.0.2 2018-05-24
* Makes iDEAL `name` parameter optional, also accepts empty string as `nil` [#940](https://github.com/stripe/stripe-ios/pull/940)
Expand Down
10 changes: 10 additions & 0 deletions Stripe/PublicHeaders/STPSourceEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ typedef NS_ENUM(NSInteger, STPSourceType) {
*/
STPSourceTypeP24,

/**
An EPS source. @see https://stripe.com/docs/sources/eps
*/
STPSourceTypeEPS,

/**
A Multibanco source. @see https://stripe.com/docs/sources/multibanco
*/
STPSourceTypeMultibanco,

/**
An unknown type of source.
*/
Expand Down
33 changes: 33 additions & 0 deletions Stripe/PublicHeaders/STPSourceParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,39 @@ NS_ASSUME_NONNULL_BEGIN
+ (STPSourceParams *)masterpassParamsWithCartId:(NSString *)cartId
transactionId:(NSString *)transactionId;

/**
Create params for an EPS source
@see https://stripe.com/docs/sources/eps

@param amount The amount to charge the customer.
@param name The full name of the account holder.
@param returnURL The URL the customer should be redirected to
after the authorization process.
@param statementDescriptor A custom statement descriptor for the
payment (optional).

@return An STPSourceParams object populated with the provided values.
*/
+ (STPSourceParams *)epsParamsWithAmount:(NSUInteger)amount
name:(NSString *)name
returnURL:(NSString *)returnURL
statementDescriptor:(nullable NSString *)statementDescriptor;

/**
Create params for a Multibanco source
@see https://stripe.com/docs/sources/multibanco

@param amount The amount to charge the customer.
@param returnURL The URL the customer should be redirected to after the
authorization process.
@param email The full email address of the customer.

@return An STPSourceParams object populated with the provided values.
*/
+ (STPSourceParams *)multibancoParamsWithAmount:(NSUInteger)amount
returnURL:(NSString *)returnURL
email:(NSString *)email;

@end

NS_ASSUME_NONNULL_END
2 changes: 2 additions & 0 deletions Stripe/STPSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ @implementation STPSource
@"three_d_secure": @(STPSourceTypeThreeDSecure),
@"alipay": @(STPSourceTypeAlipay),
@"p24": @(STPSourceTypeP24),
@"eps": @(STPSourceTypeEPS),
@"multibanco": @(STPSourceTypeMultibanco),
};
}

Expand Down
30 changes: 30 additions & 0 deletions Stripe/STPSourceParams.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,36 @@ + (STPSourceParams *)masterpassParamsWithCartId:(NSString *)cartId
return params;
}

+ (STPSourceParams *)epsParamsWithAmount:(NSUInteger)amount
name:(NSString *)name
returnURL:(NSString *)returnURL
statementDescriptor:(nullable NSString *)statementDescriptor {
STPSourceParams *params = [self new];
params.type = STPSourceTypeEPS;
params.amount = @(amount);
params.currency = @"eur"; // EPS must always use eur
params.owner = @{ @"name": name };
params.redirect = @{ @"return_url": returnURL };

if (statementDescriptor.length > 0) {
params.additionalAPIParameters = @{ @"statement_descriptor": statementDescriptor };
}

return params;
}

+ (STPSourceParams *)multibancoParamsWithAmount:(NSUInteger)amount
returnURL:(NSString *)returnURL
email:(NSString *)email {
STPSourceParams *params = [self new];
params.type = STPSourceTypeMultibanco;
params.currency = @"eur"; // Multibanco must always use eur
params.amount = @(amount);
params.redirect = @{ @"return_url": returnURL };
params.owner = @{ @"email": email };
return params;
}

#pragma mark - Redirect Dictionary

/**
Expand Down
77 changes: 77 additions & 0 deletions Tests/Tests/STPSourceFunctionalTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,81 @@ - (void)testRetrieveSource_sofort {
[self waitForExpectationsWithTimeout:5.0f handler:nil];
}

- (void)testCreateSource_eps {
STPSourceParams *params = [STPSourceParams epsParamsWithAmount:1099
name:@"Jenny Rosen"
returnURL:@"https://shop.example.com/crtABC"
statementDescriptor:@"ORDER AT123"];
params.metadata = @{@"foo": @"bar"};

STPAPIClient *client = [[STPAPIClient alloc] initWithPublishableKey:apiKey];
XCTestExpectation *expectation = [self expectationWithDescription:@"Source creation"];
[client createSourceWithParams:params completion:^(STPSource *source, NSError * error) {
XCTAssertNil(error);
XCTAssertNotNil(source);
XCTAssertEqual(source.type, STPSourceTypeEPS);
XCTAssertEqualObjects(source.amount, params.amount);
XCTAssertEqualObjects(source.currency, params.currency);
XCTAssertEqualObjects(source.owner.name, params.owner[@"name"]);
XCTAssertEqual(source.redirect.status, STPSourceRedirectStatusPending);
XCTAssertEqualObjects(source.redirect.returnURL, [NSURL URLWithString:@"https://shop.example.com/crtABC"]);
XCTAssertNotNil(source.redirect.url);
XCTAssertEqualObjects(source.metadata, params.metadata);
XCTAssertEqualObjects(source.allResponseFields[@"statement_descriptor"], @"ORDER AT123");

[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0f handler:nil];
}

- (void)testCreateSource_eps_no_statement_descriptor {
STPSourceParams *params = [STPSourceParams epsParamsWithAmount:1099
name:@"Jenny Rosen"
returnURL:@"https://shop.example.com/crtABC"
statementDescriptor:nil];
params.metadata = @{@"foo": @"bar"};

STPAPIClient *client = [[STPAPIClient alloc] initWithPublishableKey:apiKey];
XCTestExpectation *expectation = [self expectationWithDescription:@"Source creation"];
[client createSourceWithParams:params completion:^(STPSource *source, NSError * error) {
XCTAssertNil(error);
XCTAssertNotNil(source);
XCTAssertEqual(source.type, STPSourceTypeEPS);
XCTAssertEqualObjects(source.amount, params.amount);
XCTAssertEqualObjects(source.currency, params.currency);
XCTAssertEqualObjects(source.owner.name, params.owner[@"name"]);
XCTAssertEqual(source.redirect.status, STPSourceRedirectStatusPending);
XCTAssertEqualObjects(source.redirect.returnURL, [NSURL URLWithString:@"https://shop.example.com/crtABC"]);
XCTAssertNotNil(source.redirect.url);
XCTAssertEqualObjects(source.metadata, params.metadata);
XCTAssertNil(source.allResponseFields[@"statement_descriptor"]);

[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0f handler:nil];
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think multibanco needs a functional test too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right slipped my mind

- (void)testCreateSource_multibanco {
STPSourceParams *params = [STPSourceParams multibancoParamsWithAmount:1099
returnURL:@"https://shop.example.com/crtABC"
email:@"user@example.com"];
params.metadata = @{@"foo": @"bar"};

STPAPIClient *client = [[STPAPIClient alloc] initWithPublishableKey:apiKey];
XCTestExpectation *expectation = [self expectationWithDescription:@"Source creation"];
[client createSourceWithParams:params completion:^(STPSource *source, NSError * error) {
XCTAssertNil(error);
XCTAssertNotNil(source);
XCTAssertEqual(source.type, STPSourceTypeMultibanco);
XCTAssertEqualObjects(source.amount, params.amount);
XCTAssertEqual(source.redirect.status, STPSourceRedirectStatusPending);
XCTAssertEqualObjects(source.redirect.returnURL, [NSURL URLWithString:@"https://shop.example.com/crtABC"]);
XCTAssertNotNil(source.redirect.url);
XCTAssertEqualObjects(source.metadata, params.metadata);

[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0f handler:nil];
}

@end
12 changes: 12 additions & 0 deletions Tests/Tests/STPSourceParamsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ - (void)testType {
sourceParams.rawTypeString = @"p24";
XCTAssertEqual(sourceParams.type, STPSourceTypeP24);

sourceParams.rawTypeString = @"eps";
XCTAssertEqual(sourceParams.type, STPSourceTypeEPS);

sourceParams.rawTypeString = @"multibanco";
XCTAssertEqual(sourceParams.type, STPSourceTypeMultibanco);

sourceParams.rawTypeString = @"unknown";
XCTAssertEqual(sourceParams.type, STPSourceTypeUnknown);

Expand Down Expand Up @@ -106,6 +112,12 @@ - (void)testSetType {
sourceParams.type = STPSourceTypeP24;
XCTAssertEqualObjects(sourceParams.rawTypeString, @"p24");

sourceParams.type = STPSourceTypeEPS;
XCTAssertEqualObjects(sourceParams.rawTypeString, @"eps");

sourceParams.type = STPSourceTypeMultibanco;
XCTAssertEqualObjects(sourceParams.rawTypeString, @"multibanco");

sourceParams.type = STPSourceTypeUnknown;
XCTAssertNil(sourceParams.rawTypeString);
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/Tests/STPSourceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ - (void)testTypeFromString {
XCTAssertEqual([STPSource typeFromString:@"p24"], STPSourceTypeP24);
XCTAssertEqual([STPSource typeFromString:@"P24"], STPSourceTypeP24);

XCTAssertEqual([STPSource typeFromString:@"eps"], STPSourceTypeEPS);
XCTAssertEqual([STPSource typeFromString:@"EPS"], STPSourceTypeEPS);

XCTAssertEqual([STPSource typeFromString:@"multibanco"], STPSourceTypeMultibanco);
XCTAssertEqual([STPSource typeFromString:@"MULTIBANCO"], STPSourceTypeMultibanco);

XCTAssertEqual([STPSource typeFromString:@"unknown"], STPSourceTypeUnknown);
XCTAssertEqual([STPSource typeFromString:@"UNKNOWN"], STPSourceTypeUnknown);

Expand All @@ -81,6 +87,8 @@ - (void)testStringFromType {
@(STPSourceTypeThreeDSecure),
@(STPSourceTypeAlipay),
@(STPSourceTypeP24),
@(STPSourceTypeEPS),
@(STPSourceTypeMultibanco),
@(STPSourceTypeUnknown),
];

Expand Down Expand Up @@ -116,6 +124,12 @@ - (void)testStringFromType {
case STPSourceTypeP24:
XCTAssertEqualObjects(string, @"p24");
break;
case STPSourceTypeEPS:
XCTAssertEqualObjects(string, @"eps");
break;
case STPSourceTypeMultibanco:
XCTAssertEqualObjects(string, @"multibanco");
break;
case STPSourceTypeUnknown:
XCTAssertNil(string);
break;
Expand Down