Skip to content

Commit

Permalink
Merge pull request #92 from qonversion/feature/sc-34726/purchaseWitho…
Browse files Browse the repository at this point in the history
…utOptions

Added ability to call purchase without providing any options.
  • Loading branch information
SpertsyanKM authored Sep 4, 2024
2 parents 2725d4d + ffc79d7 commit 1a29900
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
4 changes: 2 additions & 2 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<param name="android-package" value="com.qonversion.android.sdk.QonversionPlugin"/>
</feature>
</config-file>
<framework src="io.qonversion.sandwich:sandwich:5.1.2" />
<framework src="io.qonversion.sandwich:sandwich:5.1.3" />
<source-file src="src/android/QonversionPlugin.java" target-dir="src/com/qonversion/android/sdk" />
<source-file src="src/android/EntitiesConverter.java" target-dir="src/com/qonversion/android/sdk" />
<source-file src="src/android/Utils.java" target-dir="src/com/qonversion/android/sdk" />
Expand All @@ -75,7 +75,7 @@
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="QonversionSandwich" spec="5.1.2" />
<pod name="QonversionSandwich" spec="5.1.3" />
</pods>
</podspec>
</platform>
Expand Down
5 changes: 4 additions & 1 deletion plugin/src/android/QonversionPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public void purchase(
CallbackContext callbackContext
) {
try {
List<String> contextKeysList = EntitiesConverter.convertArrayToStringList(contextKeys);
List<String> contextKeysList = contextKeys == null
? null
: EntitiesConverter.convertArrayToStringList(contextKeys);

qonversionSandwich.purchase(
productId,
offerId,
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/plugin/QonversionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface QonversionApi {
*
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
purchaseProduct(product: Product, options: PurchaseOptions): Promise<Map<string, Entitlement>>
purchaseProduct(product: Product, options: PurchaseOptions | undefined): Promise<Map<string, Entitlement>>

/**
* Make a purchase and validate it through server-to-server using Qonversion's Backend.
Expand Down
9 changes: 7 additions & 2 deletions plugin/src/plugin/QonversionInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {RemoteConfigList} from "./RemoteConfigList";
import {UserProperties} from './UserProperties';
import {PurchaseModel} from './PurchaseModel';
import {PurchaseUpdateModel} from './PurchaseUpdateModel';
import {PurchaseOptions} from "./PurchaseOptions";;
import {PurchaseOptions} from "./PurchaseOptions";
import {PurchaseOptionsBuilder} from './PurchaseOptionsBuilder';

const sdkVersion = "6.1.0";

Expand Down Expand Up @@ -63,8 +64,12 @@ export default class QonversionInternal implements QonversionApi {
}
}

async purchaseProduct(product: Product, options: PurchaseOptions): Promise<Map<string, Entitlement>> {
async purchaseProduct(product: Product, options: PurchaseOptions | undefined): Promise<Map<string, Entitlement>> {
try {
if (!options) {
options = new PurchaseOptionsBuilder().build();
}

let args: any[] = [product.qonversionID]
if (isIos()) {
args = [...args, options.quantity, options.contextKeys];
Expand Down
4 changes: 2 additions & 2 deletions sample/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const app = {
const products = await Qonversion.getSharedInstance().products();
const product = products.get(productId);
try {
const purchaseModel = product.toPurchaseModel(offerId);
const entitlements = await Qonversion.getSharedInstance().purchase(purchaseModel);
const purchaseOptions = !!offerId ? new Qonversion.PurchaseOptionsBuilder().setOfferId(offerId) : undefined;
const entitlements = await Qonversion.getSharedInstance().purchaseProduct(product, purchaseOptions);
console.log('Qonversion purchase:', entitlements, productId);
} catch (e) {
console.log('Qonversion purchase failed', e);
Expand Down
30 changes: 20 additions & 10 deletions sample/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ cordova-plugin-device@^3.0.0:
integrity sha512-g8fFYOvleeYpklWvHwZ/T8/IzJe/3O0MGVDIUoqBru4v8SNDAbNVD3oOqoOQANBWGFQMg7GIkAAl8errCHZ7zQ==

"cordova-plugin-qonversion@file:../plugin":
version "6.0.1"
version "6.1.0"
resolved "file:../plugin"

cross-spawn@^7.0.1, cross-spawn@^7.0.3:
Expand Down Expand Up @@ -276,7 +276,17 @@ fs-extra@^10.1.0:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^9.0.0, fs-extra@^9.1.0:
fs-extra@^9.0.0:
version "9.1.0"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz"
integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^9.1.0:
version "9.1.0"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz"
integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==
Expand Down Expand Up @@ -365,10 +375,10 @@ ios-sim@^8.0.2:
plist "^3.0.1"
simctl "^2"

is-core-module@^2.11.0:
version "2.12.1"
resolved "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.1.tgz"
integrity sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==
is-core-module@^2.13.0:
version "2.13.0"
resolved "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.0.tgz"
integrity sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==
dependencies:
has "^1.0.3"

Expand Down Expand Up @@ -571,11 +581,11 @@ rechoir@^0.6.2:
resolve "^1.1.6"

resolve@^1.1.6:
version "1.22.2"
resolved "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz"
integrity sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==
version "1.22.4"
resolved "https://registry.npmjs.org/resolve/-/resolve-1.22.4.tgz"
integrity sha512-PXNdCiPqDqeUou+w1C2eTQbNfxKSuMxqTCuvlmmMsk1NWHL5fRrhY6Pl0qEYYc6+QqGClco1Qj8XnjPego4wfg==
dependencies:
is-core-module "^2.11.0"
is-core-module "^2.13.0"
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

Expand Down

0 comments on commit 1a29900

Please sign in to comment.