PHP code example of paymaya / paymaya-sdk

1. Go to this page and download the library: Download paymaya/paymaya-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/ */

    

paymaya / paymaya-sdk example snippets


// Used for composer based installation
lation
// 

//
PayMayaSDK::getInstance()->initCheckout(<PUBLIC_API_KEY>, <SECRET_API_KEY>, <ENVIRONMENT>);

// Checkout
$itemCheckout = new Checkout();
$user = new User();
$itemCheckout->buyer = $user->buyerInfo();

// Item
$itemAmountDetails = new ItemAmountDetails();
$itemAmountDetails->shippingFee = "14.00";
$itemAmountDetails->tax = "5.00";
$itemAmountDetails->subtotal = "50.00";
$itemAmount = new ItemAmount();
$itemAmount->currency = "PHP";
$itemAmount->value = "69.00";
$itemAmount->details = $itemAmountDetails;
$item = new Item();
$item->name = "Leather Belt";
$item->code = "pm_belt";
$item->description = "Medium-sized belt made from authentic leather";
$item->quantity = "1";
$item->amount = $itemAmount;
$item->totalAmount = $itemAmount;

$itemCheckout->items = array($item);
$itemCheckout->totalAmount = $itemAmount;
$itemCheckout->requestReferenceNumber = "123456789";
$itemCheckout->redirectUrl = array(
	"success" => "https://shop.com/success",
	"failure" => "https://shop.com/failure",
	"cancel" => "https://shop.com/cancel"
	);

$itemCheckout->execute();

echo $itemCheckout->id // Checkout ID
echo $itemCheckout->url // Checkout URL

$itemCheckout->retrieve();

/* The following properties will be populated
 *  $status
	*  $paymentType
	*  $transactionReferenceNumber
	*  $receiptNumber;
	*  $paymentStatus;
	*  $voidStatus;
	*  $metadata;
	*/
	


$shopCustomization = new Customization();
$shopCustomization->logoUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg";
$shopCustomization->iconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico";
$shopCustomization->appleTouchIconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico";
$shopCustomization->customTitle = "Checkout Page Title";
$shopCustomization->colorScheme = "#368d5c";

$shopCustomization->set();

echo "Logo URL: " . $shopCustomization->logoUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg
echo "Icon URL: " . $shopCustomization->iconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico
echo "Apple Touch Icon URL: " . $shopCustomization->appleTouchIconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico
echo "Custom Title: " . $shopCustomization->customTitle . "\n";
// Checkout Page Title
echo "Color Scheme: " . $shopCustomization->colorScheme . "\n";
// #368d5c

$shopCustomization->get();

echo "Logo URL: " . $shopCustomization->logoUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg
echo "Icon URL: " . $shopCustomization->iconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico
echo "Apple Touch Icon URL: " . $shopCustomization->appleTouchIconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico
echo "Custom Title: " . $shopCustomization->customTitle . "\n";
// Checkout Page Title
echo "Color Scheme: " . $shopCustomization->colorScheme . "\n";
// #368d5c

$shopCustomization->remove();

echo "Logo URL: " . $shopCustomization->logoUrl . "\n";
// null
echo "Icon URL: " . $shopCustomization->iconUrl . "\n";
// null
echo "Apple Touch Icon URL: " . $shopCustomization->appleTouchIconUrl . "\n";
// null
echo "Custom Title: " . $shopCustomization->customTitle . "\n";
// null
echo "Color Scheme: " . $shopCustomization->colorScheme . "\n";
// null

$successWebhook = new Webhook();
$successWebhook->name = Webhook::CHECKOUT_SUCCESS;
$successWebhook->callbackUrl = "http://shop.someserver.com/success";

$successWebhook->register();

$successWebhook->callbackUrl .= "Updated";
$successWebhook->update();

// $successWebhook->callbackUrl = "http://shop.someserver.com/successUpdated"

$successWebhook->delete();

Webhook::retrieve();