Giter VIP home page Giter VIP logo

chromeos / pwa-play-billing Goto Github PK

View Code? Open in Web Editor NEW
58.0 58.0 19.0 4.59 MB

This sample demonstrates how you can publish your Progressive Web App (PWA) on Google Play Store with Trusted Web Activities (TWA), and use Digital Goods API and Payment Request API to receive payments with Google Play Billing.

License: Apache License 2.0

TypeScript 49.66% JavaScript 44.81% HTML 4.41% CSS 1.11%
digital-goods-api google-play google-play-developer-api google-play-store payment-request-api progressive-web-app pwa rtdn trusted-web-activity twa

pwa-play-billing's People

Contributors

dependabot[bot] avatar ibrahimkarahan avatar joycetoh8 avatar lukeingalls avatar nohe427 avatar snugug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pwa-play-billing's Issues

Dependabot

Can we get dependabot installed in this repo for keeping up to date with things?

Why don't we have a.ISO version of CHROME OS FLEX .BIN

CHROME OS FLEX.ISO VS .BIN
💐If we have👉.ISO form of,
Eg. Chrome OS Flex👉.ISO 
👉Instead of Chrome OS Flex 👉 .BIN, then we will be able Use Chrome OS Flex in
👉multi Boot USB (like Ventoy), along with
👉 multiple softwares like antivirus+ driver+
👉 battery of recovery softwares, other OS ETC. Along with Chrome OS Flex👉.ISO:
👉All in one USB drive
👉 As majority of other bootable, softwares comes 
👉in.ISO format.
👉 utility, 👉recovery,
👉installations, Utility of CHROME OS FLEX. 👉ISO will increase a lot.
👉If we have👉.ISO form

THANKS A LOT

No support for any development environment

I am presently working with a PWA, and have to incorporate the Google Play Billing API so subscriptions can be purchased.

There doesn't appear to be any way to develop the javascript in a local development environment like Visual Studio. It seems the APIs just flat out don't run, unless you deploy the code on a properly packaged app released through Google Play. Even creating internal test releases is at least a 20 minute routine (compile PWA, deploy to web space, use PWABuilder to create package, extract aab file and upload to Google Play console to create new release, download to phone/device, clear cache, run...)

Most developers (myself included) develop code incrementally, we start simple, run the code, if it works, embellish and add next task, otherwise fix and try again, Even Google's own youtube videos on using this API develop in this way! This is what development environments are for. There are very few developers who can read API docs, look at sample code, then knock out 40 lines of javascript that works first time.

Is there really no way to get the APIs to work in a dev environment? I totally understand why these APIs for production purposes are only available in properly trusted apps, but there has to be some kind of sandbox or dummy option to help developers, even if it is only using fixed test data and demo payments. Nobody can pose any security threat using sandbox demo APIs and it would hugely reduce the time required to get working code.

Because a 20 minute round trip each time I want to make a change to the javascript during development is just not a practical or viable way to work.

Can this sample code even run without being incorporated and deployed to an actual release app?

Testing Locally?

We are trying to add Digial Goods API to our PWA so we can get it on the store. This sample is very useful particularly the readme. the big problem tho is how to test it locally?

We are running Windows 10 Chrome 93 Stable and getDigitalGoodsService" in window always seems to return false..

We have also tried on a ChromeBook 93 Stable and still cant get it even if we enable the various experimental flags AND add the origin trial token etc etc..

Any ideas?

The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.

Hi,

Thanks for such a helpful sample and guide, we have used it to successfully manage to make a purchase on ChromeOS using Google Play Billing.

The problem however is when we come to fetch the purchase from the api (https://github.com/chromeos/pwa-play-billing/blob/main/functions/src/purchases.ts#L81) then we get the following error:

Error: The current user has insufficient permissions to perform the requested operation.

I am sure I am using the correct keys attached to the service account that is linked in the Google Play Console.

Just to be sure I used this page to test the API: https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptions/get

And I get a different error:

{
  "error": {
    "code": 403,
    "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.",
    "errors": [
      {
        "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.",
        "domain": "androidpublisher",
        "reason": "projectNotLinked"
      }
    ]
  }
}

Which is really odd because it is linked.

It seems like there are a great many people that have had the same issue: https://stackoverflow.com/questions/25481207/error-the-project-id-used-to-call-the-google-play-developer-api-has-not-been-l

I have followed the suggestions listed on there (delete and recreate the store item) to no avail.

We are really kind of stuck and not sure what to do, any clues?

Persistent "Payment method https://play.google.com/billing is not supported"

We've been stuck for days trying to implement Google Play Billing in our TWA. We have experience with Billing, having implemented it on our native Android app, but we just can't seem to get past this error.

We've been following this guide to a T, but upon trying to make a new PaymentRequest, we receive the the following error:

Uncaught DOMException: The payment method "https://play.google.com/billing" is not supported.

We've ensured ensured "playBilling": {"enabled": true} is in our manifest.json, which would be the most likely culprit. We've cleared Chrome's cache/storage, etc. And in general, it seems like our TWA is configured correctly, as everything else seems to work and there is no URL bar displayed at any point in the app's lifecycle.

What could be the problem here? One of the only people we've seen run into this issue was here, but they had the URL bar showing which led them to discover their assetlinks.json was incorrect, whereas there's no indication that our assetlinks.json is wrong. Code is below.

//Billing
window.billingService

var googleBilling = async function(){
	if ('getDigitalGoodsService' in window) {
	  	// Digital Goods API is supported!
	 	try {
		    window.billingService = await window.getDigitalGoodsService('https://play.google.com/billing');

		    console.log("getDigitalGoodsService is here")
		    // Check and redeem purchases
			const existingPurchases = await window.billingService["listPurchases"];

			if (existingPurchases.length == 0){
				console.log("No Purchases")
			} else {
				for (const p in existingPurchases) {
 		 	    	// Update the UI with items the user is already entitled to.
			   		console.log(`Users has entitlement for ${p.itemId}`);
				}
			}
		
			var skuDetailFun = async function(){
				var semester = $('#semesterSelect').val();
				var hostSite = window.location.host.split(".")[0];
				var prodToShow = ""

				if (hostSite == "coursicle"){
					prodToShow = "com.coursicle.coursicle."+semester+"premium"
				} else {
					prodToShow = "dev.coursicle.coursicle."+semester+"premium"
				}		    
			   
			    var skuDetails = await window.billingService.getDetails([prodToShow]);

			    console.log("sku details", skuDetails);

				for (var index in skuDetails) {
					var item = skuDetails[index]
			 		// Format the price according to the user locale.
			  		const localizedPrice = new Intl.NumberFormat(
			   			navigator.language,
			    		{style: 'currency', currency: item.price.currency}
			    	).format(item.price.value);

			  		// Render the price to the UI.
			  		//renderProductDetails(
			        //item.itemId, item.title, localizedPrice, item.description);
				}	
			}

			skuDetailFun();
			
		} catch (error) {
		    console.log("Google Play Billing is not available. Use another payment flow.", error);
		    return;
		}
	}

}

async function makePurchase(service, sku) {
   // Define the preferred payment method and item ID
   const paymentMethods = [{
       supportedMethods: ["https://play.google.com/billing"],
       data: {
           sku: sku,
       },
   }];

 	const paymentDetails = {
	    total: {
	        label: `Total`,
	        amount: {currency: `USD`, value: `0`}
	    }
	};

	var request = new PaymentRequest(paymentMethods, paymentDetails);
	
	try {	
		const paymentResponse = await request.show();
		const {purchaseToken} = paymentResponse.details;

	    // Call backend to validate and acknowledge the purchase.
	    if (await acknowledgePurchaseOnBackend(purchaseToken, sku)) {
	        // Optional: tell the PaymentRequest API the validation was
	        // successful. The user-agent may show a "payment successful"
	        // message to the user.
	        const paymentComplete = await paymentResponse.complete('success');
	    } else {
	        // Optional: tell the PaymentRequest API the validation failed. The
	        // user agent may show a message to the user.
	        const paymentComplete = await paymentResponse.complete('fail');
	    }
	} catch (error) {
	    if (error.message.includes('was cancelled')) {
	        // User dismissed native dialog
	        logWarning('User chose not to subscribe:', error);
	    } else {
	        // Report unexpected error
	        reportError(error, 'PaymentRequest.show() failed');
	    }
	    return;
	}
}	


$(document).on('click', '#premiumSetting', function(){
	console.log("do I exist")
	
	var semester = $('#semesterSelect').val();
	var hostSite = window.location.host.split(".")[0];
	var prodToShow = ""

	if (hostSite == "coursicle"){
		prodToShow = "com.coursicle.coursicle."+semester+"premium"
	} else {
		prodToShow = "dev.coursicle.coursicle."+semester+"premium"
	}

	//const service = await window.getDigitalGoodsService('https://play.google.com/billing');
	console.log(prodToShow)
	makePurchase(window.billingService,prodToShow)

})

googleBilling();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.