-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[MBL-1393] Moves Stripe Intent Logic Into It's Own Service #2050
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bb14d01
Create StripeIntentService that creates a new payment intent
scottkicks 72277fb
update existing .createPaymentIntent call sites
scottkicks 58fd985
Add setup intent func to StripeIntentServiceType
scottkicks aacc8d7
update existing createStripeSetupIntent call sites
scottkicks e253233
Merge branch 'main' into scott/post-campaign-vm-refactor
scottkicks 92e89c4
Merge branch 'main' into scott/post-campaign-vm-refactor
scottkicks c78839f
convert service to class so that it can be tested more easily
scottkicks 0d334c9
tests for StripeSetupIntentService
scottkicks 6f289e3
Merge branch 'main' into scott/post-campaign-vm-refactor
scottkicks 0d90620
clean up tests
scottkicks 8113c18
Merge branch 'main' into scott/post-campaign-vm-refactor
scottkicks 5fc37eb
Merge branch 'main' into scott/post-campaign-vm-refactor
scottkicks 13da714
inject stripe intent service only where needed instead of putting it β¦
scottkicks 36dc310
remove tests
scottkicks 09c1265
update MockStripeIntentService to use apiService
scottkicks 4f432e8
inject MockStripeIntentService into PledgePaymentMethodsViewModelTestβ¦
scottkicks 0bd6f53
inject MockStripeIntentService into PaymentMethodSettingsViewModelTesβ¦
scottkicks 76708ed
inject MockStripeIntentService into PostCampaignCheckoutViewModelTestβ¦
scottkicks 627c785
make assertion comment clearer
scottkicks 4832c8c
Merge branch 'main' into scott/post-campaign-vm-refactor
scottkicks d371d6e
cleanup from initial testing pattern
scottkicks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Foundation | ||
import KsApi | ||
import ReactiveSwift | ||
|
||
public protocol StripeIntentServiceType { | ||
func createPaymentIntent(for projectId: String, pledgeTotal: Double) | ||
-> SignalProducer<PaymentIntentEnvelope, ErrorEnvelope> | ||
func createSetupIntent( | ||
for projectId: String?, | ||
context: GraphAPI.StripeIntentContextTypes | ||
) -> SignalProducer<ClientSecretEnvelope, ErrorEnvelope> | ||
} | ||
|
||
/// This is the module that creates either a Stripe payment intent or a setup intent. | ||
public class StripeIntentService: StripeIntentServiceType { | ||
public init() {} | ||
|
||
/** | ||
Returns a signal producer that emits a `PaymentIntentEnvelope` or `ErrorEnvelope` value representing whether or not a payment intent was created and returned successfully. | ||
The returned producer emits once and completes. | ||
|
||
- parameter for: The types to register that we will request permissions for. | ||
- parameters: | ||
- projectId: The GraphID of a project | ||
- pledgeTotal: The final pledge total of the current pledge | ||
*/ | ||
|
||
public func createPaymentIntent( | ||
for projectId: String, | ||
pledgeTotal: Double | ||
) -> SignalProducer<PaymentIntentEnvelope, ErrorEnvelope> { | ||
AppEnvironment.current.apiService | ||
.createPaymentIntentInput(input: CreatePaymentIntentInput( | ||
projectId: projectId, | ||
amountDollars: String(format: "%.2f", pledgeTotal), | ||
digitalMarketingAttributed: nil | ||
)) | ||
} | ||
|
||
/** | ||
Returns a signal producer that contains a `ClientSecretEnvelope` or `ErrorEnvelope` representing whether or not a setup intent was created and returned successfully. | ||
The returned producer emits once and completes. | ||
|
||
- parameter for: The types to register that we will request permissions for. | ||
- parameters: | ||
- projectId: The optional GraphID of a project | ||
- context: The context for which this intent is being created | ||
*/ | ||
|
||
public func createSetupIntent( | ||
for projectId: String?, | ||
context: GraphAPI.StripeIntentContextTypes | ||
) -> SignalProducer<ClientSecretEnvelope, ErrorEnvelope> { | ||
AppEnvironment.current.apiService | ||
.createStripeSetupIntent( | ||
input: CreateSetupIntentInput(projectId: projectId, context: context) | ||
) | ||
} | ||
} |
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,46 @@ | ||
@testable import KsApi | ||
@testable import Library | ||
import ReactiveSwift | ||
|
||
public class MockStripeIntentService: StripeIntentServiceType { | ||
public private(set) var setupIntentRequests: Int = 0 | ||
public private(set) var paymentIntentRequests: Int = 0 | ||
|
||
public init() {} | ||
|
||
public func createPaymentIntent( | ||
for projectId: String, | ||
pledgeTotal: Double | ||
) -> SignalProducer<PaymentIntentEnvelope, ErrorEnvelope> { | ||
assert( | ||
AppEnvironment.current.apiService as? MockService != nil, | ||
"AppEnvironment.current.apiService should be a MockService when used in test." | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π nice assert |
||
|
||
self.paymentIntentRequests += 1 | ||
|
||
return AppEnvironment.current.apiService | ||
.createPaymentIntentInput(input: CreatePaymentIntentInput( | ||
projectId: projectId, | ||
amountDollars: String(format: "%.2f", pledgeTotal), | ||
digitalMarketingAttributed: nil | ||
)) | ||
} | ||
|
||
public func createSetupIntent( | ||
for projectId: String?, | ||
context: GraphAPI.StripeIntentContextTypes | ||
) -> SignalProducer<ClientSecretEnvelope, ErrorEnvelope> { | ||
assert( | ||
AppEnvironment.current.apiService as? MockService != nil, | ||
"AppEnvironment.current.apiService should be a MockService when used in test." | ||
) | ||
|
||
self.setupIntentRequests += 1 | ||
|
||
return AppEnvironment.current.apiService | ||
.createStripeSetupIntent( | ||
input: CreateSetupIntentInput(projectId: projectId, context: context) | ||
) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this pattern for dependencies!