Skip to content

A Symfony Bundle for simple integration of Payment subscription by ApplePay and GooglePlay Billing

License

Notifications You must be signed in to change notification settings

ivanhubar/iap-symfony-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iap-symfony-bundle

MIT License

A Symfony Bundle for simple integration of Payment subscription by ApplePay and GooglePlay Billing

Installation

Use composer:
composer require ivanhubar/iap-symfony-bundle

How to use

ApplePay

Verify subscription by receipt

use IvanHubar\HubarIAPBundle\Modules\ApplePay\Service\ApplePayServiceInterface;

readonly class ExampleService
{
    // Autowire Apple Pay service for verify
    public function __construct(
        private ApplePayServiceInterface $applePayService,
    )
    {
    }

    public function verify(string $receipt)
    {
        $response = $this->applePayService->verifyReceipt($receipt);
        // Do something with response from Apple
    }
}

U can see documentation from apple here: Link

Catch Apple Server Notifications

Example
<?php

namespace App\API\Modules\Subscription\Apple;

use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use IvanHubar\HubarIAPBundle\Modules\ApplePay\Service\ServerNotification\ServerNotificationProcessorInterface;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

#[OA\Tag('Endpoints')]
class ServerNotificationApiController extends AbstractFOSRestController
{
    public function __construct(
        private readonly ServerNotificationProcessorInterface $serverNotificationProcessor,
    ) {
    }

    #[Rest\Post('/api/apple/server-notification/v2')]
    #[OA\Post('/api/apple/server-notification/v2', summary: 'API route for Apple Server Notifications')]
    public function __invoke(Request $request): Response
    {
        return $this->serverNotificationProcessor->process($request);
    }
}

Then App\Modules\Subscription\EventSubscriber\Apple\AppleServerNotificationEventSubscriber will be dispatched

GooglePlayBilling

Get response by purchaseToken

use IvanHubar\HubarIAPBundle\Modules\GooglePlay\Service\GooglePlayServiceInterface;

readonly class ExampleService
{
    public function __construct(
        private GooglePlayServiceInterface $googlePlayService,
    )
    {
    }

    public function get(string $purchaseToken)
    {
        $response = $this->googlePlayService->getSubscriptionByPurchaseTokenV2($purchaseToken);
    }
}

To acknowledge subscription use method acknowledgeSubscription()

Catch Google RTDNs

Example
<?php

namespace App\API\Modules\Subscription\Google;

use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use IvanHubar\HubarIAPBundle\Modules\GooglePlay\Service\RTDN\RTDNSubscriptionServiceInterface;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

#[OA\Tag(name: 'Endpoints')]
class GoogleRTDNApiController extends AbstractFOSRestController
{
    public function __construct(
        private readonly RTDNSubscriptionServiceInterface $service,
    ) {
    }

    #[Rest\Post(path: '/api/google/rtdn')]
    #[OA\Post(path: '/api/google/rtdn', summary: 'API route for Google Real Time Developer Notifications (RTDNs)')]
    public function __invoke(Request $request): JsonResponse
    {
        return $this->service->processRTDN($request);
    }
}

Then IvanHubar\HubarIAPBundle\Modules\GooglePlay\Event\RTDN\RTDNSubscriptionReceivedEvent will be dispatched

To decode Google RTDN use method decodeRTDN

About

A Symfony Bundle for simple integration of Payment subscription by ApplePay and GooglePlay Billing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages