Giter Site home page Giter Site logo

s4b0t / laravel-paddle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from protonemedia/laravel-paddle

0.0 1.0 0.0 96 KB

Paddle.com API integration for Laravel with support for webhooks/events

Home Page: https://protone.media/en/blog/a-new-laravel-package-to-handle-payments-and-subscriptions-with-paddle

License: MIT License

PHP 99.50% HTML 0.50%

laravel-paddle's Introduction

Laravel Paddle

Latest Version on Packagist Build Status Quality Score Total Downloads

This package provides an integration with Paddle.com for Laravel 5.8 and higher. Read the blogpost about the introduction of the package!

Features

  • Super easy wrapper around the Paddle.com API
  • Built-in support for Webhooks and Event handling
  • Blade directive to use Paddle.js in your front-end
  • Compatible with Laravel 5.8 and 6.0.
  • PHP 7.2, 7.3 or 7.4 required.

Installation

You can install the package via composer:

composer require protonemedia/laravel-paddle

Configuration

Publish the config and view files:

php artisan vendor:publish --provider="ProtoneMedia\LaravelPaddle\PaddleServiceProvider"

Set your Vendor ID and Code and the Public Key settings in your .env file or in the config/paddle.php file. The Public Key is used to verify incoming webhooks from Paddle.

PADDLE_VENDOR_ID=123
PADDLE_VENDOR_AUTH_CODE=456
PADDLE_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----"

Usage

The API calls are available with the Paddle facade. Check out the the documentation to learn all about the Paddle API. You can build your API calls fluently or you could simply pass an array which holds the data. This package has some basic validation rules for the given data and this might result in an InvalidDataException if your data is invalid. Whenever an API call fails it will throw a PaddleApiException.

// Fluent:
$paddleResponse = Paddle::product()
    ->generatePayLink()
    ->productId($paddlePlanId)
    ->customerEmail($team->owner->email)
    ->passthrough(['team_id' => $team->id])
    ->send();

// Array with payload:
$payload = [
    'product_id' => $paddlePlanId,
    'customer_email' => $team->owner->email,
    'passthrough' => ['team_id' => $team->id],
];

$paddleResponse = Paddle::product()
    ->generatePayLink($payload)
    ->send();

return Redirect::to($paddleResponse['url']);

Available API calls

// alerts
Paddle::alert()->getWebhookHistory();

// checkouts
Paddle::checkout()->getOrderDetails();
Paddle::checkout()->getUserHistory();
Paddle::checkout()->getPrices();

// products
Paddle::product()->listCoupons();
Paddle::product()->createCoupon();
Paddle::product()->updateCoupon();
Paddle::product()->deleteCoupon();

Paddle::product()->listProducts();
Paddle::product()->generateLicense();
Paddle::product()->generatePayLink();
Paddle::product()->listTransactions($entity, $id);

// subscriptions
Paddle::subscription()->listPlans();
Paddle::subscription()->createPlan();

Paddle::subscription()->listUsers();
Paddle::subscription()->updateUser();
Paddle::subscription()->previewUpdate();
Paddle::subscription()->cancelUser();

Paddle::subscription()->listModifiers();
Paddle::subscription()->createModifier();
Paddle::subscription()->deleteModifier();

Paddle::subscription()->listPayments();
Paddle::subscription()->reschedulePayment();
Paddle::subscription()->createOneOffCharge($subscriptionId);

Webhooks and Laravel Events

You can configure your webhook URI in the paddle.php config file. Update your webhook settings at Paddle accordingly. By default the URI is paddle/webhook. This means that the webhook calls will be posted to https://your-domain.com/paddle/webhook.

Every webhook will be mapped to an Event and contains the payload of the webhook. For example when the Subscription Created webhook is called, the request is verified and a SubscriptionCreated event will be fired.

Events:

  • ProtoneMedia\LaravelPaddle\Events\HighRiskTransactionCreated
  • ProtoneMedia\LaravelPaddle\Events\HighRiskTransactionUpdated
  • ProtoneMedia\LaravelPaddle\Events\LockerProcessed
  • ProtoneMedia\LaravelPaddle\Events\NewAudienceMember
  • ProtoneMedia\LaravelPaddle\Events\PaymentDisputeClosed
  • ProtoneMedia\LaravelPaddle\Events\PaymentDisputeCreated
  • ProtoneMedia\LaravelPaddle\Events\PaymentRefunded
  • ProtoneMedia\LaravelPaddle\Events\PaymentSucceeded
  • ProtoneMedia\LaravelPaddle\Events\SubscriptionCancelled
  • ProtoneMedia\LaravelPaddle\Events\SubscriptionCreated
  • ProtoneMedia\LaravelPaddle\Events\SubscriptionPaymentFailed
  • ProtoneMedia\LaravelPaddle\Events\SubscriptionPaymentRefunded
  • ProtoneMedia\LaravelPaddle\Events\SubscriptionPaymentSucceeded
  • ProtoneMedia\LaravelPaddle\Events\SubscriptionUpdated
  • ProtoneMedia\LaravelPaddle\Events\TransferCreated
  • ProtoneMedia\LaravelPaddle\Events\TransferPaid
  • ProtoneMedia\LaravelPaddle\Events\UpdateAudienceMember

When you register a listener to handle the event, the payload is easily accessible:

<?php

namespace App\Listeners;

use ProtoneMedia\LaravelPaddle\Events\SubscriptionCreated;

class CreateSubscriptionModel
{
    public function handle(SubscriptionCreated $event)
    {
        $status = $event->status;

        $nextBillDate = $event->next_bill_date;

        // or

        $webhookData = $event->all();
    }
}

Blade directive

This directive imports the Paddle JavaScript library and configures it with your Vendor ID.

<body>
    {{-- your app --}}

    @paddle
</body>

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-paddle's People

Contributors

pascalbaljet avatar

Watchers

 avatar

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.