Download the PHP package simpleclick/laravel-purchases without Composer

On this page you can find all versions of the php package simpleclick/laravel-purchases. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-purchases

Packagist PHP Version Support Latest Version on Packagist Total Downloads GitHub last commit

✅ App Store ✅ Google Play

Laravel In-App purchase

Google Play and App Store provide the In-App Purchase (IAP) services. IAP can be used to sell a variety of content, including subscriptions, new features, and services. The purchase event and the payment process occurs on and handled by the mobile application (iOS and Android), then your backend needs to be informed about this purchase event to deliver the purchased product or update the user's subscription state.

Laravel In-App purchase comes to help you to parse and validate the purchased products and handle the different states of a subscription, like New subscription , auto-renew, cancellation, expiration and etc.

Table of contents

Installation

Install the package via composer:

composer require imdhemy/laravel-purchases

Publish the config file:

php artisan vendor:publish --provider="Imdhemy\Purchases\PurchaseServiceProvider" --tag="config"

Configuration

The published config file config/purchase.php looks like:

Each configuration option is illustrated in the configuration section.

i. Generic Configurations:

The generic configurations are not specific to a particular provider of the two supported providers (Google and Apple).

i.1 Routing

This package adds two POST endpoints to receive the Real-Time Developer Notifications, and the The App Store Server Notifications.

Provider URI Name
Google Play /purchases/subscriptions/google purchase.serverNotifications.google
App Store /purchases/subscriptions/apple purchase.serverNotifications.apple

These routes can be configured through the routing key in the config file. For example:

i.2 Event Listeners

Your application should handle the different states of a subscription life. Each state update triggers a specified event. You can create an event listener to update your backend on each case.

Add the created listener to the associated event key.

All events extend the \Imdhemy\Purchases\Events\PurchaseEvent abstract class, which implements the \Imdhemy\Purchases\Contracts\PurchaseEventContract interface. Check the Purchase Events section for more information.

ii. Google Play Configurations:

The following set of configurations are specific to google play:

ii.1 Google Application Credentials

Requests to the Google Play Developer API, requires authentication and scopes. To authenticate your machine create a service account, then upload the downloaded JSON file google-app-credentials.json to your server, and finally add GOOGLE_APPLICATION_CREDENTIALS key to your .env file and set it to the path of JSON file.

  1. In the Cloud Console, go to the Create service account key page.
  2. From the Service account list, select New service account.
  3. In the Service account name field, enter a name.
  4. From the Role list, select Project > Owner.
  5. Click Create. A JSON file that contains your key downloads to your computer.
  6. Upload the JSON file to your storage directory, or any other protected directory.
  7. Set the .env key GOOGLE_APPLICATION_CREDENTIALS to the JSON file path.

ii.2 Google Play Package Name

The package name of the application for which this subscription was purchased (for example, 'com.some.thing').

iii. App Store Configurations

The following set of configurations are specific to the App Store.

iii.1 App Store Sandbox

The configuration key appstore_sandbox is a boolean value that determines whether the requests sent to the App Store are in the sandbox or not.

iii.2 App Store Password

Request to the App Store requires the key appstore_password to be set. Your app’s shared secret, which is a hexadecimal string.

Sell Products

Google Products

You can use the \Imdhemy\Purchases\Facades\Product facade to acknowledge or to get the receipt data from Google Play as follows:

Each key has a getter method prefixed with get, for example: getKind() to get the kind value. For more information check:

  1. Google Developer documentation.
  2. PHP Google Play Billing Package.

App Store Products

You can use the \Imdhemy\Purchases\Facades\Product to send a verifyReceipt request to the App Store. as follows:

As usual each key has a getter method.

For more information check:

  1. App Store Documentation
  2. PHP App Store IAP package

Sell Subscriptions

Google Play Subscriptions

You can use the \Imdhemy\Purchases\Facades\Subscription facade to acknowledge or to get the receipt data from Google Play as follows:

The SubscriptionPurchase resource indicates the status of a user's inapp product purchase. This is its JSON Representation:

For more information check:

  1. Google Developer documentation.
  2. PHP Google Play Billing Package.

App Store Subscriptions

You can use the \Imdhemy\Purchases\Facades\Subscription to send a verifyReceipt request to the App Store. as follows:

For more information check:

  1. Validating Receipts with the App Store
  2. PHP App Store IAP package

Purchase Events

As mentioned the configuration section, Your application should handle the different states of a subscription life. Each state update triggers a specified event. You can create an event listener to update your backend on each case.

All triggered events implement Imdhemy\Purchases\Contracts\PurchaseEventContract interface, which allows you to get a standard representation of the received notification through the getServerNotification() method.

The retrieved notification is of type \Imdhemy\Purchases\Contracts\ServerNotificationContract which allows you to get a standard representation of the subscription using the getSubscription() method.

The subscription object provides the following methods:

  1. getExpiryTime() returns a Time object that tells the expiration time of the subscription.
  2. getItemId() returns the purchased subscription id.
  3. getProvider() returns the provider of this subscription, either google_play or app_store.
  4. getUniqueIdentifier() returns a unique identifier for this subscription.
  5. getProviderRepresentation() returns either SubscriptionPurchase or ReceiptResponse based on the provider.

Here is an example of an auto-renewed subscription:

Testing

TODO: add testing examples.


All versions of laravel-purchases with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-json Version *
imdhemy/appstore-iap Version ^0.3
nesbot/carbon Version ^2.41
simpleclick/google-play-billing Version ^0.6.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package simpleclick/laravel-purchases contains the following files

Loading the files please wait ....