PHP code example of moffhub / connector-sdk

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

    

moffhub / connector-sdk example snippets


use Moffhub\ConnectorSdk\BaseConnector;
use Moffhub\MpsSpec\Contracts\HasChargeCapability;
use Moffhub\MpsSpec\Data\{ChargeRequest, ChargeResponse, ConfigField, ConnectorManifest};
use Moffhub\MpsSpec\Enums\{Capability, Channel, ChargeStatus, SettlementModel};

final class AcmeConnector extends BaseConnector implements HasChargeCapability
{
    public function manifest(): ConnectorManifest
    {
        return new ConnectorManifest(
            connectorId: 'acme',
            displayName: 'Acme Payments',
            version: '1.0.0',
            specVersion: '0.1',
            vendorName: 'Acme Inc.',
            vendorWebsite: 'https://acme.example',
            vendorSupportEmail: '[email protected]',
            supportedChannels: [Channel::Card],
            supportedCurrencies: ['USD'],
            capabilities: [Capability::Payment],
            settlementModel: SettlementModel::T1,
            

$connector = new AcmeConnector();
$connector->initialize([
    'api_key' => $_ENV['ACME_KEY'],
    'environment' => 'live',
]);

$response = $connector->createCharge(new ChargeRequest(/* ... */));

use Moffhub\ConnectorSdk\Support\HttpClient;

$client = new HttpClient(baseUri: 'https://api.acme.example', timeout: 10);
$response = $client->post('/charges', [
    'headers' => ['Authorization' => "Bearer {$apiKey}"],
    'json' => $payload,
]);

use Moffhub\ConnectorSdk\Support\WebhookVerifier;

$verifier = new WebhookVerifier(secret: $this->/ Throws WebhookVerificationFailedException on mismatch

use Moffhub\ConnectorSdk\SandboxConnector;

$connector = new SandboxConnector();
$connector->initialize([]);
$response = $connector->createCharge($request); // returns deterministic fake data