Download the PHP package rgalstyan/larapi without Composer
On this page you can find all versions of the php package rgalstyan/larapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rgalstyan/larapi
More information about rgalstyan/larapi
Files in rgalstyan/larapi
Package larapi
Short Description Laravel package for Pi Network payment system
License MIT
Homepage https://github.com/rgalstyan/larapi
Informations about the package larapi
Package Installation
Requirements
- PHP 8.1+
- Laravel 10+
- Composer
Step 1: Install via Composer
Run the following command to install the package:
Step 2: Publish the Configuration (Optional)
If you need to modify the default settings, publish the config file:
Step 3: Environment Configuration
Add the required environment variables to your .env file:
Step 4: Run Migrations
If you have exported the larapi-migrations configurations, run:
Using Package Functions
Overview
This package integrates the Pi Network API into Laravel and provides two main services:
- LaraPiDbService: Manages all database operations for Pi payments using
PaymentDTOobjects, including creating, updating, deleting, and retrieving payment records along with their associated statuses and transactions. - LaraPiPaymentService: Handles communication with the Pi Network API. It provides methods to create, approve, complete, cancel payments, and retrieve payment details.
LaraPiDbService
The LaraPiDbService is responsible for managing the payment data stored in your local database. Below are the key methods:
- createPayment(PaymentDTO $dto): PiPayment – Creates a new payment record. This method checks for duplicate payment identifiers, creates associated payment status and transaction records, and returns the created payment. In case of errors, the transaction is rolled back and the error is logged.
- updatePayment(int \$paymentId, PaymentDTO \$dto): PiPayment – Updates an existing payment record along with its related status or transaction data.
- deletePayment(int $paymentId): bool – Deletes a payment record by its ID.
- getPaymentById(int $paymentId): ?PiPayment – Retrieves a payment record by its ID.
- getPaymentsByUserId(int $userId): ?object – Retrieves all payment records for a specific user based on the user ID.
- getPaymentsByUserUid(string $piUserUid): ?object – Retrieves all payments associated with a specific Pi user UID.
LaraPiPaymentService
The LaraPiPaymentService is used to interact directly with the Pi Network API. Its main methods include:
- createPayment(float \$amount, string \$uid, string \$memo = 'A2U Payment', array $metadata = []): PaymentDTO|null – Sends a payment creation request to the API. On success, it returns a
PaymentDTOcontaining the payment details. - getPayment(string $paymentId): PaymentDTO|null – Retrieves payment details from the API for the given payment ID.
- approvePayment(string $paymentId): PaymentDTO|null – Approves a pending payment by sending the appropriate request to the API.
- completePayment(string \$paymentId, string $txid): PaymentDTO|null – Completes a payment by providing the transaction ID (
txid) to the API. - cancelPayment(string $paymentId): PaymentDTO|null – Cancels a pending payment through an API call.
- incompleteServerPayments(): object|null – Retrieves server-side payments that have not yet been completed, allowing further processing or error handling.
Example Usage
The following examples demonstrate how you can use these services within your Laravel application:
Example 1: Creating a Payment
Example 2: Updating a Payment
All versions of larapi with dependencies
illuminate/console Version ^10.0|^11.0|^12.0
illuminate/contracts Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.0