Skip to content
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

fix: price field for android #114

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: yarn test
- name: Pre-Release package
if: github.ref == 'refs/heads/next'
run: npm run release -- --ci --preRelease=beta --verbose
run: npm run release -- --ci --preRelease=beta -VV
env:
NPM_TOKEN: ${{ secrets.RN_SDK_NPM_WRITE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chargebee.android.reactnative.utils

import com.android.billingclient.api.SkuDetails
import com.chargebee.android.models.CBProduct
import com.chargebee.android.reactnative.models.PurchaseResult
import com.chargebee.android.models.SubscriptionDetailsWrapper
Expand Down Expand Up @@ -38,11 +39,15 @@ internal fun convertProductToDictionary(product: CBProduct): WritableMap {
val writableMap: WritableMap = WritableNativeMap()
writableMap.putString("id", product.productId)
writableMap.putString("title", product.productTitle)
writableMap.putString("price", product.productPrice)
writableMap.putDouble("price", convertPriceAmountInMicros(product.skuDetails))
writableMap.putString("currencyCode", product.skuDetails.priceCurrencyCode)
return writableMap
}

fun convertPriceAmountInMicros(skuDetails: SkuDetails): Double {
return skuDetails.priceAmountMicros / 1_000_000.0
}

internal fun convertPurchaseResultToDictionary(product: PurchaseResult, status: Boolean): WritableMap {
val writableMap: WritableMap = WritableNativeMap()
writableMap.putString("subscription_id", product.subscriptionId)
Expand Down
2 changes: 2 additions & 0 deletions example/src/screens/ProductDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ const ProductDetail = ({ navigation, route }) => {

async function fetchProductDetails(productId: string) {
try {
console.log("Fetching product details")
const productsDetail: Array<Product> = await Chargebee.retrieveProducts([
productId,
]);
console.log("Fetched product details:", productsDetail)
setSelectedProductDetail(productsDetail[0]);
} catch (error) {
console.error('Product Details fetch failed', error);
Expand Down
2 changes: 1 addition & 1 deletion ios/CBProduct+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension CBProduct {
var productDictionary: [String: Any] = [:]
productDictionary["id"] = skProduct.productIdentifier
productDictionary["title"] = skProduct.localizedTitle
productDictionary["price"] = skProduct.price
productDictionary["price"] = skProduct.price.doubleValue
productDictionary["currencyCode"] = skProduct.priceLocale.currencyCode
return productDictionary
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@
"hooks": {
"after:git:afterRelease": [
"git checkout -b docs-v${version}",
"git push origin docs-v${version}",
"git push origin v${version}"
"git push origin docs-v${version}"
]
},
"npm": {
"publish": true
},
"github": {
"release": true
"release": true,
"draft": true
},
"plugins": {
"@release-it/conventional-changelog": {
Expand Down
2 changes: 1 addition & 1 deletion src/Purchases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface AuthenticationDetail {
export interface Product {
readonly id: string;
readonly title: string;
readonly price: string;
readonly price: Double;
readonly currencyCode: string;
}

Expand Down