Skip to content

Commit 9eaaa5b

Browse files
author
contoriel
committed
update version & readme
1 parent 460c8a8 commit 9eaaa5b

File tree

1,400 files changed

+79870
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,400 files changed

+79870
-0
lines changed

README.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
InApp Billing for Cafe Bazaar (Android)
2+
=============
3+
**React Native Cafe Bazaar** is built to provide an easy interface to InApp Billing for **Cafe Bazaar**,
4+
5+
6+
## Installation
7+
8+
1. `npm install --save react-native-cafe-bazaar`
9+
2. Add the following in `android/setting.gradle`
10+
11+
```gradle
12+
...
13+
include ':react-native-cafe-bazaar', ':app'
14+
project(':react-native-cafe-bazaar').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cafe-bazaar/android')
15+
```
16+
17+
3. And the following in `android/app/build.gradle`
18+
19+
```gradle
20+
...
21+
dependencies {
22+
...
23+
compile project(':react-native-cafe-bazaar')
24+
}
25+
```
26+
27+
4. Update MainActivity or MainApplication depending on React Native version.
28+
- React Native version >= 0.29
29+
Edit `MainApplication.java`.
30+
1. Add `import com.contoriel.cafebazaar.CafeBazaarPackage;`
31+
2. Register package:
32+
```java
33+
@Override
34+
protected List<ReactPackage> getPackages() {
35+
return Arrays.<ReactPackage>asList(
36+
new MainReactPackage(),
37+
// add package here
38+
new CafeBazaarPackage()
39+
);
40+
}
41+
```
42+
43+
5. Add your CafeBazaar Public key as a line to your `android/app/src/main/res/values/strings.xml` with the name `CAFE_BAZAAR_PUBLIC_KEY`. For example:
44+
```xml
45+
<string name="CAFE_BAZAAR_PUBLIC_KEY">YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE</string>
46+
```
47+
Alternatively, you can add your license key as a parameter when registering the `CafeBazaarPackage`, like so:
48+
```java
49+
.addPackage(new CafeBazaarPackage("YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE"))
50+
```
51+
or for React Native 29+
52+
```java
53+
new CafeBazaarPackage("YOUR_CAFE_BAZAAR_PUBLIC_KEY_HERE")
54+
```
55+
56+
57+
58+
### ON THE BAZAAR DEVELOPER PANEL
59+
60+
1. Upload the application to the [Developer Panel][panel].
61+
62+
[panel]: https://cafebazaar.ir/developers/panel/apps/?l=en "Cafe Bazaar Developer Panel"
63+
64+
2. Using the **Enter** button in In-app Billing column of the created app,
65+
go to In-app Billing Panel.
66+
67+
3. In that app, create your in-app items
68+
69+
4. Grab the application's public key (a base-64 string) You can find the application's public key in the **Dealer Apps**
70+
page for your application.
71+
72+
73+
## Javascript API
74+
Most of methods returns a `Promise`.
75+
76+
### open()
77+
78+
**Important:** Opens the service channel to CafeBazaar. Must be called (once!) before any other billing methods can be called.
79+
80+
```javascript
81+
CafeBazaar.open()
82+
.then(() => CafeBazaar.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST));
83+
```
84+
85+
### close()
86+
**Important:** Must be called to close the service channel to CafeBazaar, when you are done doing billing related work. Failure to close the service channel may degrade the performance of your app.
87+
```javascript
88+
CafeBazaar.open()
89+
.then(() => CafeBazaar.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST))
90+
.then((details) => {
91+
console.log(details)
92+
return CafeBazaar.close()
93+
});
94+
```
95+
96+
### purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
97+
##### Parameter(s)
98+
* **productSKU (required):** String
99+
* **developerPayload:** String
100+
* **rcRequest:** Integer
101+
102+
##### Returns:
103+
* **Details:** JSONObject:
104+
* **mDeveloperPayload:**
105+
* **mItemType:**
106+
* **mOrderId:**
107+
* **mOriginalJson:**
108+
* **mPackageName:**
109+
* **mPurchaseState:**
110+
* **mPurchaseTime:**
111+
* **mSignature:**
112+
* **mSku:**
113+
* **mToken:**
114+
115+
```javascript
116+
CafeBazaar.purchase('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
117+
.then((details) => {
118+
console.log(details)
119+
});
120+
```
121+
122+
### consume('YOUR_SKU')
123+
##### Parameter(s)
124+
* **productSKU (required):** String
125+
126+
##### Returns:
127+
* **Details:** JSONObject:
128+
* **mDeveloperPayload:**
129+
* **mItemType:**
130+
* **mOrderId:**
131+
* **mOriginalJson:**
132+
* **mPackageName:**
133+
* **mPurchaseState:**
134+
* **mPurchaseTime:**
135+
* **mSignature:**
136+
* **mSku:**
137+
* **mToken:**
138+
139+
```javascript
140+
CafeBazaar.consume('YOUR_SKU').then(...);
141+
```
142+
143+
### loadOwnedItems()
144+
145+
##### Returns:
146+
* **items:** JSONArray:
147+
148+
149+
```javascript
150+
CafeBazaar.loadOwnedItems()
151+
.then((details) => {
152+
console.log(details)
153+
});
154+
```
155+
156+
### loadInventory([item1_SKU,item2_SKU,...])
157+
##### Parameter(s)
158+
* **productSKUs (required):** Array<String>
159+
160+
##### Returns:
161+
* **mPurchaseMap:** JSONObject
162+
* **mSkuMap:** JSONObject
163+
164+
```javascript
165+
CafeBazaar.loadInventory([]).then(...);
166+
```
167+
168+
## Use event listener
169+
Below function dispatch **Event** instead of **Promise** and return value is same.
170+
171+
### purchaseWithEvent('YOUR_SKU','DEVELOPER_PAYLOAD',RC_REQUEST)
172+
### consumeWithEvent('YOUR_SKU')
173+
### loadOwnedItemsWithEvent()
174+
175+
176+
```javascript
177+
import {DeviceEventEmitter} from 'react-native';
178+
...
179+
componentDidMount(){
180+
DeviceEventEmitter.addListener('CafeBazaar', function(e: Event) {
181+
// handle event.
182+
console.log(e);
183+
});
184+
}
185+
186+
187+
### BACK TO BAZAAR DEVELOPER PANEL
188+
189+
1. Upload the updated APK to Bazaar Developer Panel

android/app/BUCK

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# To learn about Buck see [Docs](https://buckbuild.com/).
2+
# To run your application with Buck:
3+
# - install Buck
4+
# - `npm start` - to start the packager
5+
# - `cd android`
6+
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7+
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8+
# - `buck install -r android/app` - compile, install and run application
9+
#
10+
11+
lib_deps = []
12+
13+
for jarfile in glob(['libs/*.jar']):
14+
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15+
lib_deps.append(':' + name)
16+
prebuilt_jar(
17+
name = name,
18+
binary_jar = jarfile,
19+
)
20+
21+
for aarfile in glob(['libs/*.aar']):
22+
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23+
lib_deps.append(':' + name)
24+
android_prebuilt_aar(
25+
name = name,
26+
aar = aarfile,
27+
)
28+
29+
android_library(
30+
name = "all-libs",
31+
exported_deps = lib_deps,
32+
)
33+
34+
android_library(
35+
name = "app-code",
36+
srcs = glob([
37+
"src/main/java/**/*.java",
38+
]),
39+
deps = [
40+
":all-libs",
41+
":build_config",
42+
":res",
43+
],
44+
)
45+
46+
android_build_config(
47+
name = "build_config",
48+
package = "com.cafebazaar",
49+
)
50+
51+
android_resource(
52+
name = "res",
53+
package = "com.cafebazaar",
54+
res = "src/main/res",
55+
)
56+
57+
android_binary(
58+
name = "app",
59+
keystore = "//android/keystores:debug",
60+
manifest = "src/main/AndroidManifest.xml",
61+
package_type = "debug",
62+
deps = [
63+
":app-code",
64+
],
65+
)

android/app/build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apply plugin: "com.android.library"
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.1"
6+
defaultConfig {
7+
minSdkVersion 16
8+
targetSdkVersion 22
9+
versionCode 1
10+
versionName "1.0"
11+
}
12+
buildTypes {
13+
release {
14+
minifyEnabled false
15+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
16+
}
17+
}
18+
}
19+
20+
dependencies {
21+
compile 'com.intellij:annotations:+@jar'
22+
compile 'com.google.code.gson:gson:2.2.4'
23+
compile "com.facebook.react:react-native:+" // From node_modules
24+
}

0 commit comments

Comments
 (0)