Skip to content

Commit

Permalink
fix: price field for android (#114)
Browse files Browse the repository at this point in the history
* build: updates release and package files to make github releases as optional

* fix: price for android
  • Loading branch information
cb-haripriyan authored Apr 27, 2023
1 parent 949bae4 commit c22e701
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
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

0 comments on commit c22e701

Please sign in to comment.