PHP code example of iss / laravel-maya-sdk

1. Go to this page and download the library: Download iss/laravel-maya-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iss / laravel-maya-sdk example snippets


return [
    "public_key" => env('MAYA_PUBLIC_KEY', ""),
    "private_key" => env('MAYA_PRIVATE_KEY', ""),

   // other configurations...
];

use Iss\LaravelMayaSdk\Facades\Maya;


$itemService = Maya::item();
$itemService->addItem([
    "amount" => [
        "value" => 1200
    ],
    "totalAmount" => [
        "value" => 1200
    ],
    "name" => "Shoes",
    "code" => "SHOE-1",
    "description" => "Nike Shoes",
    "quantity" => "1"
]);


use Iss\LaravelMayaSdk\Facades\Maya;


$itemService = Maya::item();
$totalAmountService = Maya::totalAmount();

$totalAmountService->setItems($itemService->getItems());
$totalAmountService->setDiscount("0.05");
$totalAmountService->setCurrency("PHP");
$totalAmountService->setServiceCharge("100");
$totalAmountService->setShippingFee("250");
$totalAmountService->setTax("100");


$totalAmountService = Maya::totalAmount();

$totalAmountService->setItems(Maya::item()->getItems());
$totalAmountService->setDiscount("0.05");
$totalAmountService->setCurrency("PHP");
$totalAmountService->setServiceCharge("100");
$totalAmountService->setShippingFee("250");
$totalAmountService->setTax("100");

return $totalAmountService->get();

[
    "currency" => "PHP",
    "value" => 1649.95, // float
    "details" => [
        "discount" => "0.05",
        "serviceCharge" => "100",
        "shippingFee" => "250",
        "tax" => "100",
        "subtotal" => "1200"
    ]
];

use Iss\LaravelMayaSdk\Facades\Maya;


$shippingService = Maya::shippingAddress();
$shippingService->setFirstName('Test First Name')
    ->setLastName('Test Last Name')
    ->setPhone('+63912345678')
    ->setEmail('[email protected]')
    ->setCity('Test City')
    ->setLine1('Test Line 1')
    ->setLine2('Test Line 2')
    ->setState('Test State')
    ->setZipCode("2222")
    ->setCountryCode("PH");

use Iss\LaravelMayaSdk\Facades\Maya;

$billingService = Maya::billingAddress();
$billingService->setLine1('Test Line 1');
$billingService->setLine2('Test Line  2');
$billingService->setCity('Test City');
$billingService->setState('Test State');
$billingService->setZipCode("2222");
$billingService->setCountryCode("PH");

use Iss\LaravelMayaSdk\Facades\Maya;

$buyerService = Maya::buyer();
$buyerService->setFirstName('Jerson')
    ->setLastName('Ramos')
    ->setEmail('[email protected]')
    ->setPhone('+639052537600');

$buyerService->setShippingAddress(Maya::shippingAddress()->get());

$buyerService->setBillingAddress(Maya::billingAddress()->get());

use Iss\LaravelMayaSdk\Facades\Maya;


$redirectService = Maya::redirect();
$redirectService->setCancel(route('checkout.cancel') . '?id=' . $custom_uuid);
$redirectService->setFailure(route('checkout.failure') . '?id=' . $custom_uuid);
$redirectService->setSuccess(route('checkout.success') . '?id=' . $custom_uuid);


$parameters = [
    "totalAmount" => Maya::totalAmount()->get(),
    "items" => Maya::item()->getItems(),
    "buyer" => Maya::buyer()->get(),
    "redirectUrl" => Maya::redirect()->getRedirectUrls(),
    "requestReferenceNumber" => $custom_uuid
];

$checkoutService = Maya::checkout();
return $checkoutService->checkout($parameters);


[
  "data" => [
    'checkoutId' => '',
    'redirectUrl' => ''
  ],
  "code" => 200,
  "message" => "success",
]

use Iss\LaravelMayaSdk\Facades\Maya;

return Maya::webhook()->get();

[
  "data" => [
    {
        "id": "7549dd53-38fb-49b9-9ad8-af6223937e92",
        "name": "PAYMENT_FAILED",
        "callbackUrl": "https://store-philippines.worldcup.basketball?wc-api=cynder_paymaya_payment",
        "createdAt": "2023-04-24T06:57:35.000Z",
        "updatedAt": "2023-04-24T06:57:35.000Z"
    },
    {
        "id": "e63c832b-e9dc-426e-831f-6756bbd33bbc",
        "name": "PAYMENT_EXPIRED",
        "callbackUrl": "https://store-philippines.worldcup.basketball?wc-api=cynder_paymaya_payment",
        "createdAt": "2023-04-24T06:57:30.000Z",
        "updatedAt": "2023-04-24T06:57:30.000Z"
    }
],
  "code" => 200,
  "message" => "success",
]

return Maya::webhook()->for("PAYMENT_SUCCESS")->create('http://www.merchantsite.com/success');

[
  "data" => [
    "id" => "98397531-e6cd-4c5c-ba6c-089546098989",
    "name" => "PAYMENT_SUCCESS",
    "callbackUrl" => "http://www.merchantsite.com/success",
    "createdAt" => "2023-05-07T05:28:27.000Z",
    "updatedAt" => "2023-05-07T05:28:27.000Z"
  ],
  "code" => 200,
  "message" => "success",
]

return Maya::webhook()->getById('98397531-e6cd-4c5c-ba6c-089546098989');

[
  "data" => [
    "id" => "98397531-e6cd-4c5c-ba6c-089546098989",
    "name" => "PAYMENT_SUCCESS",
    "callbackUrl" => "http://www.merchantsite.com/success",
    "createdAt" => "2023-05-07T05:28:27.000Z",
    "updatedAt" => "2023-05-07T05:28:27.000Z"
  ],
  "code" => 200,
  "message" => "success",
]

return Maya::webhook()->update('98397531-e6cd-4c5c-ba6c-089546098989', 'http://www.merchantsite.com/success'); 

[
  "data" => [
    "id" => "98397531-e6cd-4c5c-ba6c-089546098989",
    "name" => "PAYMENT_SUCCESS",
    "callbackUrl" => "http://www.merchantsite.com/success",
    "createdAt" => "2023-05-07T05:28:27.000Z",
    "updatedAt" => "2023-05-07T05:28:27.000Z"
  ],
  "code" => 200,
  "message" => "success",
]

return Maya::webhook()->delete('98397531-e6cd-4c5c-ba6c-089546098989'); 

[
  "data" => [
    "id" => "98397531-e6cd-4c5c-ba6c-089546098989",
    "name" => "PAYMENT_SUCCESS",
    "callbackUrl" => "http://www.merchantsite.com/success",
    "createdAt" => "2023-05-07T05:28:27.000Z",
    "updatedAt" => "2023-05-07T05:28:27.000Z"
  ],
  "code" => 200,
  "message" => "success",
]

use Iss\LaravelMayaSdk\Facades\Maya;

return Maya::customization()->setLogoUrl("https://www.merchantsite.com/icon-store.b575c975.svg")
        ->setIconUrl("https://www.merchantsite.com/favicon.ico")
        ->setAppleTouchIconUrl("https://www.merchantsite.com/touch-icon-ipad-retina.png")
        ->setCustomTitle("Merchant Store")
        ->setColorScheme("#85c133")
        ->showReceipt()
        ->skipResultPage()
        ->showMerchantName()
        ->setRedirectTimer(10)
        ->set();

[
  "data" => [
    "logoUrl" => "https://www.merchantsite.com/icon-store.b575c975.svg",
    "iconUrl" => "https://www.merchantsite.com/favicon.ico",
    "appleTouchIconUrl" => "https://www.merchantsite.com/touch-icon-ipad-retina.png",
    "customTitle" => "Merchant Store",
    "colorScheme" => "#85c133",
    "redirectTimer" => 10,
    "hideReceiptInput" => false,
    "skipResultPage" => true,
    "showMerchantName" => true
],
  "code" => 200,
  "message" => "success",
]

return Maya::customization()->get();

[
  "data" => [
    "logoUrl" => "https://www.merchantsite.com/icon-store.b575c975.svg",
    "iconUrl" => "https://www.merchantsite.com/favicon.ico",
    "appleTouchIconUrl" => "https://www.merchantsite.com/touch-icon-ipad-retina.png",
    "customTitle" => "Merchant Store",
    "colorScheme" => "#85c133",
    "redirectTimer" => 10,
    "hideReceiptInput" => false,
    "skipResultPage" => true,
    "showMerchantName" => true
],
  "code" => 200,
  "message" => "success",
]

return Maya::customization()->delete();

// Blank Response
bash
  php artisan vendor:publish --tag=maya