-
Notifications
You must be signed in to change notification settings - Fork 21
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
Added context keys to purchase #625
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
db17451
Added context keys to purchase
actions-user 91c3481
Fixed warnings
actions-user eb6b239
Fixed tests
actions-user c50501f
Updated baseline
actions-user 84e66e6
Added fixes after review
actions-user 9197d9e
Fixed warnings
actions-user 800960f
Apply suggestions from code review
suriksarkisyan 2ef6427
Added fixes after review
actions-user 01dbc48
Merge branch 'feature/contextKeys' of github.com:qonversion/android-s…
actions-user 3aa2416
Fixed warnings
actions-user 2cfb99f
Fixed sample
actions-user 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
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
102 changes: 102 additions & 0 deletions
102
sdk/src/main/java/com/qonversion/android/sdk/dto/QPurchaseOptions.kt
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,102 @@ | ||
package com.qonversion.android.sdk.dto | ||
|
||
import com.qonversion.android.sdk.QonversionConfig.Builder | ||
import com.qonversion.android.sdk.dto.products.QProduct | ||
import com.qonversion.android.sdk.dto.products.QProductOfferDetails | ||
import com.qonversion.android.sdk.dto.products.QProductStoreDetails | ||
import com.squareup.moshi.JsonClass | ||
|
||
/** | ||
* Purchase options that may be used to modify purchase process. | ||
* To create an instance, use the nested [Builder] class. | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
class QPurchaseOptions internal constructor ( | ||
SpertsyanKM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
internal val contextKeys: List<String>? = null, | ||
internal val offerId: String? = null, | ||
internal val applyOffer: Boolean = true, | ||
internal val oldProduct: QProduct? = null, | ||
internal val updatePolicy: QPurchaseUpdatePolicy? = null | ||
) { | ||
/** | ||
* The builder of QPurchaseOptions instance. | ||
* | ||
* This class contains a variety of methods to customize the purchase behavior. | ||
* You can call them sequentially and call [build] finally to get the [QPurchaseOptions] instance. | ||
*/ | ||
class Builder { | ||
private var contextKeys: List<String>? = null | ||
private var offerId: String? = null | ||
private var applyOffer: Boolean = true | ||
private var oldProduct: QProduct? = null | ||
private var updatePolicy: QPurchaseUpdatePolicy? = null | ||
|
||
/** | ||
* Set the context keys associated with a purchase. | ||
* | ||
* @param contextKeys context keys for the purchase. | ||
* @return builder instance for chain calls. | ||
*/ | ||
fun setContextKeys(contextKeys: List<String>): QPurchaseOptions.Builder = apply { | ||
this.contextKeys = contextKeys | ||
} | ||
|
||
/** | ||
* Set context keys associated with a purchase. | ||
* | ||
* @param oldProduct Qonversion product from which the upgrade/downgrade | ||
* will be initialized. | ||
* @return builder instance for chain calls. | ||
*/ | ||
fun setOldProduct(oldProduct: QProduct): QPurchaseOptions.Builder = apply { | ||
this.oldProduct = oldProduct | ||
} | ||
|
||
/** | ||
* Set the update policy for the purchase. | ||
* If the [updatePolicy] is not provided, then default one | ||
* will be selected - [QPurchaseUpdatePolicy.WithTimeProration]. | ||
* @param updatePolicy update policy for the purchase. | ||
* @return builder instance for chain calls. | ||
*/ | ||
fun setUpdatePolicy(updatePolicy: QPurchaseUpdatePolicy): QPurchaseOptions.Builder = apply { | ||
this.updatePolicy = updatePolicy | ||
} | ||
|
||
/** | ||
* Set offer for the purchase. | ||
* @param offer concrete offer which you'd like to purchase. | ||
* @return builder instance for chain calls. | ||
*/ | ||
fun setOffer(offer: QProductOfferDetails): QPurchaseOptions.Builder = apply { | ||
this.offerId = offer.offerId | ||
} | ||
|
||
/** | ||
* Set the offer Id to the purchase. | ||
* If [offerId] is not specified, then the default offer will be applied. To know how we choose | ||
* the default offer, see [QProductStoreDetails.defaultSubscriptionOfferDetails]. | ||
* @param offerId concrete offer Id which you'd like to purchase. | ||
* @return builder instance for chain calls. | ||
*/ | ||
fun setOfferId(offerId: String): QPurchaseOptions.Builder = apply { | ||
this.offerId = offerId | ||
} | ||
|
||
/** | ||
* Call this function to remove any intro/trial offer from the purchase (use only a bare base plan). | ||
* @return builder instance for chain calls. | ||
*/ | ||
fun removeOffer(): QPurchaseOptions.Builder = apply { | ||
this.applyOffer = false | ||
} | ||
|
||
/** | ||
* Generate [QPurchaseOptions] instance with all the provided options. | ||
* @return the complete [QPurchaseOptions] instance. | ||
*/ | ||
fun build(): QPurchaseOptions { | ||
return QPurchaseOptions(contextKeys, offerId, applyOffer, oldProduct, updatePolicy) | ||
} | ||
} | ||
} |
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.
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.
Remove changes here