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

Increment PlayBilling version to V5 #432

Merged
merged 6 commits into from
Jul 12, 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
63 changes: 63 additions & 0 deletions playbilling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Play Billing

The Play Billing module provides capabilities for your TWA app to connect with [Google Play Billing library](https://developer.android.com/google/play/billing), for example you can:

* Query purchase history
* Initialize a payment
* Query SKU details

The module uses [Version 5](https://developer.android.com/google/play/billing/release-notes#5-2-1) of Play Billing library.


## How to use it? (Website)
To use this API from your website you can do it as follows:
```js
const PAYMENT_METHOD = 'https://play.google.com/billing';
const SKUS = [
'android.test.purchased',
'android.test.canceled',
]

const service = await window.getDigitalGoodsService(PAYMENT_METHOD);
const details = await service.getDetails(SKUS);
console.log(details);
```

## How to use it? (Android Project)
To use it from your Android project you will need to do two steps:
Add this to your `AndroidManifest.xml`

```xml
<activity
android:name="com.google.androidbrowserhelper.playbilling.provider.PaymentActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="keyboardHidden|keyboard|orientation|screenLayout|screenSize"
android:exported="true">

<intent-filter>
<action android:name="org.chromium.intent.action.PAY" />
</intent-filter>

<meta-data
android:name="org.chromium.default_payment_method_name"
android:value="https://play.google.com/billing" />
</activity>

<service
android:name="com.google.androidbrowserhelper.playbilling.provider.PaymentService"
android:exported="true" >
<intent-filter>
<action android:name="org.chromium.intent.action.IS_READY_TO_PAY" />
</intent-filter>
</service>
```

Create a new Service that extends `DelegationService` with this line in `onCreate()` method:
```java
registerExtraCommandHandler(new DigitalGoodsRequestHandler(getApplicationContext()));
```
Then add it to your AndroidManifest and make it exported (`android:exported="true"`).



You can find a working demo [here](https://github.com/GoogleChrome/android-browser-helper/tree/main/demos/twa-play-billing)
2 changes: 1 addition & 1 deletion playbilling/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {
api 'androidx.browser:browser:1.4.0'

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.billingclient:billing:4.0.0'
implementation 'com.android.billingclient:billing:5.2.1'

testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.4'
Expand Down
Loading