-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding UPI integration for iOS (#13)
* Adding UPI integration * project.pbxproj changes * project.pbxproj changes * fix linting tests * making vpa non-optional * change Upi to UPI * fix name in comments Co-authored-by: David Estes <[email protected]>
- Loading branch information
1 parent
80ed9dd
commit 1b1b4ad
Showing
11 changed files
with
248 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// STPPaymentMethodUPI.swift | ||
// StripeiOS | ||
// | ||
// Created by Anirudh Bhargava on 11/6/20. | ||
// Copyright © 2020 Stripe, Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A UPI Payment Method. | ||
/// - seealso: https://stripe.com/docs/api/payment_methods/object#payment_method_object-upi | ||
public class STPPaymentMethodUPI: NSObject, STPAPIResponseDecodable { | ||
@objc private(set) public var allResponseFields: [AnyHashable: Any] = [:] | ||
|
||
/// Customer’s Virtual Payment Address (VPA). | ||
@objc public private(set) var vpa: String | ||
|
||
// MARK: - Description | ||
/// :nodoc: | ||
@objc public override var description: String { | ||
let props = [ | ||
// Object | ||
String(format: "%@: %p", NSStringFromClass(STPPaymentMethodUPI.self), self), | ||
"vpa = \(vpa)", | ||
] | ||
|
||
return "<\(props.joined(separator: "; "))>" | ||
} | ||
|
||
// MARK: - STPAPIResponseDecodable | ||
@objc | ||
public class func decodedObject(fromAPIResponse response: [AnyHashable: Any]?) -> Self? { | ||
guard let response = response else { | ||
return nil | ||
} | ||
return self.init(dictionary: response) | ||
} | ||
|
||
required init?(dictionary dict: [AnyHashable: Any]) { | ||
let nsDict = dict as NSDictionary | ||
guard let vpa = nsDict.stp_string(forKey: "vpa") else { | ||
return nil | ||
} | ||
|
||
self.vpa = vpa | ||
|
||
super.init() | ||
allResponseFields = dict | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// STPPaymentMethodUPIParams.swift | ||
// StripeiOS | ||
// | ||
// Created by Anirudh Bhargava on 11/6/20. | ||
// Copyright © 2020 Stripe, Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// An object representing parameters used to create a UPI Payment Method | ||
public class STPPaymentMethodUPIParams: NSObject, STPFormEncodable { | ||
@objc public var additionalAPIParameters: [AnyHashable: Any] = [:] | ||
|
||
/// Customer’s Virtual Payment Address (VPA). Required. | ||
@objc public var vpa: String? | ||
|
||
@objc | ||
public class func rootObjectName() -> String? { | ||
return "upi" | ||
} | ||
|
||
@objc | ||
public class func propertyNamesToFormFieldNamesMapping() -> [String: String] { | ||
return [ | ||
NSStringFromSelector(#selector(getter:vpa)): "vpa" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// STPPaymentMethodUPIParamsTest.m | ||
// StripeiOS Tests | ||
// | ||
// Created by Anirudh Bhargava on 11/6/20. | ||
// Copyright © 2020 Stripe, Inc. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "STPTestingAPIClient.h" | ||
|
||
@interface STPPaymentMethodUPIParamsTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation STPPaymentMethodUPIParamsTests | ||
|
||
- (void)testCreateUPIPaymentMethod { | ||
STPAPIClient *client = [[STPAPIClient alloc] initWithPublishableKey:STPTestingINPublishableKey]; | ||
STPPaymentMethodUPIParams *upiParams = [STPPaymentMethodUPIParams new]; | ||
upiParams.vpa = @"somevpa@hdfcbank"; | ||
STPPaymentMethodBillingDetails *billingDetails = [STPPaymentMethodBillingDetails new]; | ||
billingDetails.name = @"Jenny Rosen"; | ||
|
||
STPPaymentMethodParams *params = [STPPaymentMethodParams paramsWithUPI:upiParams | ||
billingDetails:billingDetails | ||
metadata:@{@"test_key": @"test_value"}]; | ||
|
||
XCTestExpectation *expectation = [self expectationWithDescription:@"Payment Method UPI create"]; | ||
|
||
[client createPaymentMethodWithParams:params | ||
completion:^(STPPaymentMethod * _Nullable paymentMethod, NSError * _Nullable error) { | ||
[expectation fulfill]; | ||
|
||
XCTAssertNil(error, @"Unexpected error creating UPI PaymentMethod: %@", error); | ||
XCTAssertNotNil(paymentMethod, @"Failed to create UPI PaymentMethod"); | ||
XCTAssertNotNil(paymentMethod.stripeId, @"Missing stripeId"); | ||
XCTAssertNotNil(paymentMethod.created, @"Missing created"); | ||
XCTAssertFalse(paymentMethod.liveMode, @"Incorrect livemode"); | ||
XCTAssertEqual(paymentMethod.type, STPPaymentMethodTypeUPI, @"Incorrect PaymentMethod type"); | ||
|
||
// Billing Details | ||
XCTAssertEqualObjects(paymentMethod.billingDetails.name, @"Jenny Rosen", @"Incorrect name"); | ||
|
||
// UPI Details | ||
XCTAssertNotNil(paymentMethod.upi, @"Missing UPI"); | ||
XCTAssertEqualObjects(paymentMethod.upi.vpa, @"somevpa@hdfcbank", @"Incorrect vpa"); | ||
}]; | ||
|
||
[self waitForExpectationsWithTimeout:STPTestingNetworkRequestTimeout handler:nil]; | ||
} | ||
|
||
@end |
Oops, something went wrong.