crenata/affiliate-connector

A Connector between two Laravel Framework

v1.0.0 2022-08-15 09:45 UTC

This package is auto-updated.

Last update: 2024-05-05 06:16:35 UTC


README

GitHub top language GitHub all releases GitHub issues GitHub GitHub release (latest by date including pre-releases)

Connector

A Laravel package as connector between Affiliate with Products.

Warning

This package for internal purposes, any incoming issues won't be responded.

Installation

Run these command into your laravel project folder.

composer require crenata/affiliate-connector

Publish Configuration

You need to publish the package's config. To publish configuration, run the following command.

php artisan vendor:publish --tag=connector-config

Generate Authentication Bridge

To secure the bridge, You must generate secret key and private key to your server and client project. To generate the key, run the following command.

php artisan connector:generate

And you will see.

Server : CONNECTOR_SERVER=dc6917876732a081d1d35b225aedab5bae8e5438
Client : CONNECTOR_CLIENT=ba770d272202ad9b938638687760e2ec96a7e954b19447fd5f412c615e2c7ef7

Copy the key to the .env file each projects.

In the server section, add CONNECTOR_SERVER to .env file. And also in the client section, add CONNECTOR_CLIENT to .env file.

Usage

Make sure you're following these steps.

Create Get All Product

Create your query to get all products, and change default controller in config/connector.php to your created controller.

"api" => [
    [
        "method" => HttpMethodConstant::GET,
        "url" => "products",
        "controller" => "Crenata\AffiliateConnector\Http\Controllers\ConnectorController@getProducts" // Replace with your controller.
    ],
    ...
]

Expected Return :

[
    [
        "id" => int,
        "name" => string,
        "description" => string,
        "price" => int
    ],
    ...
]

Create Get Product With Ids

Create your query to get products using WHERE id IN(), and change default controller in config/connector.php to your created controller. At this request, you will receive query string with param ids as string that contains product ids separated by comma.

"api" => [
    [
        "method" => HttpMethodConstant::GET,
        "url" => "product-with-ids",
        "controller" => "Crenata\AffiliateConnector\Http\Controllers\ConnectorController@getProductWithIds" // Replace with your controller.
    ],
    ...
]

Expected Return :

[
    [
        "id" => int,
        "name" => string,
        "description" => string,
        "price" => int
    ],
    ...
]

Create Find Product

Create your query to get product using WHERE id, and change default controller in config/connector.php to your created controller. At this request, you will receive query string with param id as int.

"api" => [
    [
        "method" => HttpMethodConstant::GET,
        "url" => "find-product",
        "controller" => "Crenata\AffiliateConnector\Http\Controllers\ConnectorController@findProduct" // Replace with your controller.
    ],
    ...
]

Expected Return :

[
    "id" => int,
    "name" => string,
    "description" => string,
    "price" => int
]

Submit Transaction

Submit transaction data to Affiliate Database. So, Affiliate can count rewards.

$response = ConnectorRequest::getInstance()
    ->setUrl(
        ConnectorUrl::getInstance()
            ->affiliate()
            ->getUrl("submit_transaction")
    )
    ->setMethod(HttpMethodConstant::POST) // Refer to Crenata\AffiliateConnector\Constants\HttpMethodConstant
    ->setBody([
        "product_id" => 1,
        "user_email" => "user@gmail.com",
        "transaction_code" => "INV-2022-IX-05-12-00",
        "product_name" => "Product Name",
        "product_description" => "Product Desc",
        "product_price" => 100000,
        "status" => TransactionStatusConstant::PENDING // Refer to Crenata\AffiliateConnector\Constants\TransactionStatusConstant
    ])
    ->setTimeout(5)
    ->send();

$result = ConnectorResponse::getInstance()->response($response);

if ($result->isSuccess()) {
    // your code here ...
}

Authors