PHP code example of waslpay / core-php

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

    

waslpay / core-php example snippets




use GuzzleHttp\Client;
use WaslPay\Sdk\WaslPay;
use WaslPay\Sdk\Providers\WaveProvider;

$provider = new WaveProvider(
    new Client(),
    getenv('WAVE_API_KEY'),
    getenv('WAVE_WEBHOOK_SECRET'),
);
$waslPay = new WaslPay($provider);



declare(strict_types=1);

use WaslPay\Sdk\DTO\PaymentRequest;

// 1. Créer une session.
$session = $waslPay->initiatePayment(new PaymentRequest(
    amount: 1000,
    currency: 'XOF',
    reference: 'order-123',
    customerPhone: '+221770000000',
    successUrl: 'https://merchant.example/payments/success',
    failureUrl: 'https://merchant.example/payments/failed',
));

// 2. Vérifier le statut.
$statusResult = $waslPay->checkStatus($session->id);
if ($statusResult->status === PaymentStatus::Failed) {
    $error = $statusResult->error;
}

// 3. Une route webhook doit transmettre le body brut, sans json_decode préalable.
$rawBody = file_get_contents('php://input');
$event = $waslPay->handleWebhook($rawBody, getallheaders());

// 4. Rembourser. Orange Money rejette explicitement cette opération.
$refund = $waslPay->refund($session->id, 500);