-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Include swiftlint * feat: Plugin init + Setup Configurations (#1) Initialise plugin with required structure. Create structure to deal with Apple Pay. Despite being ready to deal with any kind of dictionary, provide an accelerator to read the configuration from the main bundle. Add Nimble and Quick through Cocoapods to use BDD for unit testing. * feat: Check Wallet and Payment Availability (#2) Add verification for wallet and payment availability. Payment verification is enhanced by also checking it against the configured payment networks and supported capabilities. * feat: Set Details and Trigger Payment (#3) Configure the missing payment details and, by mixing it with the configuration info, trigger the payment request. * refactor: Add DocC documentation and minor fixes. (#4) Add DocC documentation. Add empty value check and mandatory fields when fetching configuration properties. * fix: Payment Setup Verification Failed on Invalid Configuration (#5) Fix error when verifying payment setup on ReadyToPay method. If some payment network or merchant capabilities are missing, return the associated error. * fix: Errors and Contact Management (#6) Clean errors and its codes and messages accordingly. New OSPMTContact struct that allows the management of the correct shipping and billing information to use on a payment request. This is required due to a limitation on OutSystems related with nullable lists. Change the OSPMTConfigurationDelegate to OSPMTConfigurationModel, in order to comply with the new OutSystems structure. Clean code (privatise local methods and make OSPMTPayment's delegate property weak, in order to avoid possible retain cycles). * fix: Check if GivenName and FamilyName are empty (#7) * chore: Add Unreleased Section * Chore: Add Podspec (#9) * refactor: Simply Generic Method * chore: Add public podspec Add public podspec. This implies also updating the readme.md file to something more descriptive and user-friendly. * feat: Add Stripe as First Payment Gateway (#11) Add all necessary logic and changes to make payment processing using Stripe including Protocols, Factories and Models to deal with the StripePayments pod. Unit tests are included. * Feat: Add Gateway property to OSPMTDetailsModel (#12) Add `gateway` property to `OSPMTDetailsModel` struct. When authorising payment, confirm that this property corresponds to a configured gateway (on plist). * feat: Add AccessToken to Full Payment Process (#13) Add the optional parameter `accessToken` to the `OSPMTActionDelegate`'s `set` method and the `OSPMTStripeWrapper`'s `processPaymentWithDetails` method. Apply consequent changes to it. In case of a full payment is triggered but no access token is passed, a `tokenIssue` is returned. * chore: Set Release Tag Set release tag on the repo's CHANGELOG file.
- Loading branch information
1 parent
e1d22e9
commit ce50ffe
Showing
607 changed files
with
51,762 additions
and
507 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,15 @@ | ||
/// Payment Service Provider enum object | ||
enum OSPMTGateway: String { | ||
case stripe = "Stripe" | ||
} | ||
|
||
extension OSPMTGateway { | ||
|
||
/// Converts a string into a `OSPMTGateway` object. | ||
/// - Parameter text: Text to convert. | ||
/// - Returns: A `OSPMTGateway` enum object if successful. `nil` is returned in case of error. | ||
static func convert(from text: String?) -> OSPMTGateway? { | ||
guard let text = text, text.lowercased() == "stripe" else { return nil } | ||
return .stripe | ||
} | ||
} |
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,18 @@ | ||
import Foundation | ||
|
||
/// Structure responsible for creating a Wrapper for the configured Gateway. | ||
struct OSPMTGatewayFactory { | ||
/// Creates the correct wrapper for the gateway the user has configured. | ||
/// - Parameter configuration: Model with the gateway configuration information. | ||
/// - Returns: The wrapper object is everything is correctly configured. `nil` is returned otherwise. | ||
static func createWrapper(for configuration: OSPMTGatewayModel) -> OSPMTGatewayDelegate? { | ||
guard let gateway = configuration.gatewayEnum, let url = URL(string: configuration.requestURL) else { return nil } | ||
let urlRequest = URLRequest(url: url) | ||
|
||
switch gateway { | ||
case .stripe: | ||
guard let publishableKey = configuration.publishableKey else { return nil } | ||
return OSPMTStripeWrapper(urlRequest: urlRequest, publishableKey: publishableKey) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
OSPaymentsLib/Gateways/Stripe/OSPMTStripeAPIDelegate.swift
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,37 @@ | ||
import PassKit | ||
import StripePayments | ||
|
||
/// Delegate class containing the required calls for Stripe's SDK to process. | ||
protocol OSPMTStripeAPIDelegate: AnyObject { | ||
/// Sets the required publishable key, required to trigger payments through Stripe | ||
/// - Parameter publishableKey: Key obtained via Stripe's Dashboard. | ||
func set(_ publishableKey: String) | ||
|
||
/// Retrieves Stripe's Payment Method's Identifier in exchange for Apple Pay's payment request result. | ||
/// - Parameters: | ||
/// - payment: Apple Pay's payment request result. | ||
/// - completion: The exchange operation result. In case of success, it returns the Payment Method Id or an error otherwise. | ||
func getPaymentMethodId(from payment: PKPayment, _ completion: @escaping (Result<String, OSPMTError>) -> Void) | ||
} | ||
|
||
extension STPAPIClient: OSPMTStripeAPIDelegate { | ||
/// Sets the required publishable key, required to trigger payments through Stripe | ||
/// - Parameter publishableKey: Key obtained via Stripe's Dashboard. | ||
func set(_ publishableKey: String) { | ||
self.publishableKey = publishableKey | ||
} | ||
|
||
/// Retrieves Stripe's Payment Method's Identifier in exchange for Apple Pay's payment request result. | ||
/// - Parameters: | ||
/// - payment: Apple Pay's payment request result. | ||
/// - completion: The exchange operation result. In case of success, it returns the Payment Method Id or an error otherwise. | ||
func getPaymentMethodId(from payment: PKPayment, _ completion: @escaping (Result<String, OSPMTError>) -> Void) { | ||
self.createPaymentMethod(with: payment) { paymentMethod, _ in | ||
if let paymentMethod = paymentMethod { | ||
completion(.success(paymentMethod.stripeId)) | ||
} else { | ||
completion(.failure(.stripePaymentMethodCreation)) | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
OSPaymentsLib/Gateways/Stripe/OSPMTStripeRequestParametersModel.swift
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,40 @@ | ||
/// Model to manage Stripe's payment process request parameters. This is based on `OSPMTRequestParametersModel`. | ||
final class OSPMTStripeRequestParametersModel: OSPMTRequestParametersModel { | ||
let paymentMethodId: String | ||
let confirm: Bool | ||
|
||
/// Keys used to encode and decode the model. | ||
enum CodingKeys: String, CodingKey { | ||
case paymentMethodId = "payment_method" | ||
case confirm | ||
} | ||
|
||
/// Constructor method. | ||
/// - Parameters: | ||
/// - amount: Amount to charge. | ||
/// - currency: Currency to charge. | ||
/// - paymentMethodId: Stripe object that represents the customer's payment instruments. | ||
/// - confirm: Automatically confirm the triggered payment process. | ||
init(amount: Int, currency: String, paymentMethodId: String, confirm: Bool = true) { | ||
self.paymentMethodId = paymentMethodId | ||
self.confirm = confirm | ||
super.init(amount: amount, currency: currency) | ||
} | ||
|
||
/// Encodes this value into the given encoder. | ||
/// | ||
/// If the value fails to encode anything, `encoder` will encode an empty | ||
/// keyed container in its place. | ||
/// | ||
/// This function throws an error if any values are invalid for the given | ||
/// encoder's format. | ||
/// | ||
/// - Parameter encoder: The encoder to write data to. | ||
override func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
try container.encode(paymentMethodId, forKey: .paymentMethodId) | ||
try container.encode(confirm, forKey: .confirm) | ||
try super.encode(to: encoder) | ||
} | ||
} |
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,45 @@ | ||
import PassKit | ||
import StripeCore | ||
|
||
/// Object responsible for making a Stripe payment process. The Wrapper deals with all calls that are required to Stripe's SDK. | ||
final class OSPMTStripeWrapper: OSPMTGatewayDelegate { | ||
var urlRequest: URLRequest | ||
var urlSession: URLSession | ||
let apiDelegate: OSPMTStripeAPIDelegate | ||
|
||
/// Constructor method. | ||
/// - Parameters: | ||
/// - urlRequest: URL load request object. | ||
/// - urlSession: Coordinator object for network data transfer tasks. | ||
/// - publishableKey: Key required for Stripe's API to trigger calls. | ||
/// - apiDelegate: Object responsible for Stripe's API calls. | ||
init(urlRequest: URLRequest, urlSession: URLSession = .shared, publishableKey: String, apiDelegate: OSPMTStripeAPIDelegate = STPAPIClient.shared) { | ||
self.urlRequest = urlRequest | ||
self.urlSession = urlSession | ||
|
||
apiDelegate.set(publishableKey) | ||
self.apiDelegate = apiDelegate | ||
} | ||
} | ||
|
||
extension OSPMTStripeWrapper { | ||
/// Triggers the process through the configured gateway. | ||
/// - Parameters: | ||
/// - payment: Apple Pay's payment request result. | ||
/// - details: Payment details to trigger processing. | ||
/// - accessToken: Authorisation token related with a full payment type. | ||
/// - completion: Payment process result. If returns the process result in case of success or an error otherwise. | ||
func process(_ payment: PKPayment, with details: OSPMTDetailsModel, and accessToken: String, _ completion: @escaping (Result<OSPMTServiceProviderInfoModel, OSPMTError>) -> Void) { | ||
self.apiDelegate.getPaymentMethodId(from: payment) { result in | ||
switch result { | ||
case .success(let paymentMethodId): | ||
let requestParametersModel = OSPMTStripeRequestParametersModel( | ||
amount: details.paymentAmount.multiplying(by: 100).intValue, currency: details.currency, paymentMethodId: paymentMethodId | ||
) | ||
self.processURLRequest(requestParametersModel, and: accessToken, completion) | ||
case .failure(let error): | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.