-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds restore purchases capability
- Loading branch information
1 parent
ff45fd7
commit 697a1fa
Showing
19 changed files
with
265 additions
and
18 deletions.
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
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,71 @@ | ||
import React from 'react'; | ||
import { Platform, StyleSheet, View } from 'react-native'; | ||
import { Text, Card, Button, Modal } from '@ui-kitten/components'; | ||
import Chargebee from '@chargebee/react-native-chargebee'; | ||
|
||
export const RestoreSubscriptions = () => { | ||
const [visible, setVisible] = React.useState(false); | ||
const [restoreDisabled, setRestoreDisabled] = React.useState(false); | ||
const [restoreData, setRestoreData] = React.useState(''); | ||
|
||
const restorePurchases = async () => { | ||
console.log("Restoring purchases") | ||
setRestoreDisabled(true) | ||
try { | ||
const restoredSubscriptions = await Chargebee.restorePurchases(true) | ||
console.log("Restored purchases", restoredSubscriptions) | ||
console.log("Restored Subscription Id", restoredSubscriptions[0].subscriptionId) | ||
console.log("Restored Plan Id", restoredSubscriptions[0].planId) | ||
console.log("Restored Store Status", restoredSubscriptions[0].storeStatus) | ||
setRestoreData(JSON.stringify(restoredSubscriptions)) | ||
setVisible(true) | ||
} catch (error) { | ||
console.log('Restore Purchases failed', error); | ||
console.log( | ||
'=========================', | ||
Platform.OS, | ||
'=========================' | ||
); | ||
const errorModel = { | ||
code: error.code, | ||
message: error.message, | ||
userInfo: { | ||
message: error.userInfo?.message, | ||
apiErrorCode: error.userInfo?.apiErrorCode, | ||
httpStatusCode: error.userInfo?.httpStatusCode, | ||
}, | ||
}; | ||
console.error(errorModel); | ||
console.log('========================='); | ||
setRestoreData(JSON.stringify(errorModel)) | ||
setVisible(true) | ||
} | ||
} | ||
function dismissModal() { | ||
setRestoreDisabled(false) | ||
setVisible(false) | ||
} | ||
return ( | ||
<> | ||
<Button style={styles.restore} appearance='outline' disabled={restoreDisabled} onPress={() => restorePurchases()}>Restore Purchases</Button> | ||
<Modal visible={visible}> | ||
<Card disabled={true}> | ||
<Text> | ||
Restored data: | ||
{restoreData} | ||
</Text> | ||
<Button onPress={() => dismissModal()}> | ||
DISMISS | ||
</Button> | ||
</Card> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
restore: { | ||
justifyContent: 'center', | ||
} | ||
}); | ||
|
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,19 @@ | ||
// | ||
// CBInAppSubscription+Extensions.swift | ||
// ChargebeeReactNative | ||
// | ||
// Created by cb-haripriyan on 11/05/23. | ||
// | ||
|
||
import Foundation | ||
import Chargebee | ||
|
||
extension InAppSubscription { | ||
var asDictionary: [String:Any] { | ||
var inAppSubscription: [String: Any] = [:] | ||
inAppSubscription["subscriptionId"] = self.subscriptionID | ||
inAppSubscription["planId"] = self.planID | ||
inAppSubscription["storeStatus"] = self.storeStatus.rawValue | ||
return inAppSubscription | ||
} | ||
} |
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
File renamed without changes.
Oops, something went wrong.