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 4 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
64 changes: 64 additions & 0 deletions playbilling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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 Purchases history
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved
* Initialize a payment
* Query SKU details (to be moved to ProductDetails later)
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved

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 data from your website you can do it as follows:
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved
```
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved
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
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved

```
<activity
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved
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>

<!-- This service checks who calls it at runtime. -->
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved
<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’
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved
```
registerExtraCommandHandler(new DigitalGoodsRequestHandler(getApplicationContext()));
```
Then add it to your AndroidManifest and make it exported (android:exported="true").
SayedElabady marked this conversation as resolved.
Show resolved Hide resolved



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