PHP code example of faso-dev / visa-checkout-sdk

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

    

faso-dev / visa-checkout-sdk example snippets


    use FasoDev\VisaCheckoutSdk\CardData;
    use FasoDev\VisaCheckoutSdk\Config;
    use FasoDev\VisaCheckoutSdk\Credentials;
    use FasoDev\VisaCheckoutSdk\PaymentException;
    use FasoDev\VisaCheckoutSdk\VisaPay;
    
    $config = Config::make(
        Credentials::make(
            'VCO_USER_1234567890',
            'VCO_PASS_1234567890',
        ),
    );
    
    $config->putUserAgent('Your user agent'); // Optional
    $config->putTimeout(30); // seconds, default is 30, optional
    $config->putConnectTimeout(30); // seconds, optional
    $config->putProxy('Your proxy'); // optional
    $config->putBaseUrl('Your base url'); // optional, but util if VISA change the base url
    $config->putCheckoutEndpoint('Your checkout endpoint'); // optional, but util if VISA change the checkout endpoint
    $config->putRequestHeaders(['Your request headers']);// optional
    
    // create a payable instance
    $payment = VisaPay::fromConfig($config);
    
    // create a visa card
    $visaCard = CardData::make(
        'visa',
        '4111111111111111',
        '12',
        '2025',
        '123',
        'John Doe',
    );
    // create a payment
	try {
		$transaction = (new CheckoutSdk($payment))->makePayment(
			100.00,
			'USD',
			$visaCard,
			'Payment description'
		);
		if ($transaction->successfull()) {
			// add transaction info to your database(id, status, amount, currency, description, user_id, etc.)
		} elseif ($transaction->declined()) {
			// retry payment or do something
		} else {
			// notify user or do something
		}
	} catch (PaymentException $e) {
		// handle exception
		echo $e->getMessage();
	}