Git Product home page Git Product logo

gp-php-sdk's Introduction

# Vicomm PHP SDK

Installation

Install via composer (not hosted in packagist yet)

composer require vicomm/sdk

## Usage

<?php

require 'vendor/autoload.php';

use Vicomm\Vicomm;

// First setup your credentials provided by vicomm
$applicationCode = "SOME_APP_CODE";
$applicationKey = "SOME_APP_KEY";

Vicomm::init($applicationCode, $applicationKey);

Once time are set your credentials, you can use available resources.

Resources availables:

  • Card
  • Available methods: getList, delete
  • Charge
  • Available methods: create, authorize, capture, verify, refund
  • Cash
  • Available methods: generateOrder

### Card

See full documentation of these features here.

List

<?php

use Vicomm\Vicomm;
use Vicomm\Exceptions\VicommErrorException;

Vicomm::init($applicationCode, $aplicationKey);

$card = Vicomm::card();

// Success response
$userId = "1";
$listOfUserCards = $card->getList($userId);

$totalSizeOfCardList = $listOfUserCards->result_size;
$listCards = $listOfUserCards->cards;

// Get all data of response
$response = $listOfUserCards->getData();

// Catch fail response
try {
	$listOfUserCards = $card->getList("someUID");
} catch (VicommErrorException $error) {
	// Details of exception
	echo $error->getMessage();
	// You can see the logs for complete information
}

Charges

See full documentation of these features here.

Create new charge

See full documentation about this here

<?php

use Vicomm\Vicomm;
use Vicomm\Exceptions\VicommErrorException;

// Card token
$cardToken = "myAwesomeTokenCard";

$charge = Vicomm::charge();

$userDetails = [
    'id' => "1", // Field required
    'email' => "[email protected]" // Field required
];

$orderDetails = [
    'amount' => 100.00, // Field required
    'description' => "XXXXXX", // Field required
    'dev_reference' => "XXXXXX", // Field required
    'vat' => 0.00 // Field required 
];

try {
    $created = $charge->create($cardToken, $orderDetails, $userDetails);
} catch (VicommErrorException $error) {
    // See the console output for complete information
    // Access to HTTP code from vicomm service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get transaction status
$status = $created->transaction->status;
// Get transaction ID
$transactionId = $created->transaction->id;
// Get authorization code
$authCode = $created->transaction->authorization_code;

Authorize charge

See the full documentation here

<?php

use Vicomm\Vicomm;
use Vicomm\Exceptions\VicommErrorException;

// Card token
$cardToken = "myAwesomeTokenCard";

$charge = Vicomm::charge();

$userDetails = [
    'id' => "1", // Field required
    'email' => "[email protected]" // Field required
];

$orderDetails = [
    'amount' => 100.00, // Field required
    'description' => "XXXXXX", // Field required
    'dev_reference' => "XXXXXX", // Field required
    'vat' => 0.00 // Field required 
];

try {
    $authorization = $charge->authorize($cardToken, $orderDetails, $userDetails);
} catch (VicommErrorException $error) {
    // See the console output for complete information
    // Access to HTTP code from vicomm service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get transaction status
$status = $authorization->transaction->status;
// Get transaction ID
$transactionId = $authorization->transaction->id;
// Get authorization code
$authCode = $authorization->transaction->authorization_code;

Capture

See the full documentation here

Need make a authorization process

<?php

use Vicomm\Vicomm;
use Vicomm\Exceptions\VicommErrorException;

$charge = Vicomm::charge();

$authorization = $charge->authorize($cardToken, $orderDetails, $userDetails);
$transactionId = $authorization->transaction->id;

try {
    $capture = $charge->capture($transactionId);
} catch (VicommErrorException $error) {
    // See the console output for complete information
    // Access to HTTP code from vicomm service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get transaction status
$status = $capture->transaction->status;

// Make a capture with different amount
$newAmountForCapture = 1000.46;
$capture = $charge->capture($transactionId, $newAmountForCapture);

Refund

See the full documentation here

Need make a create process

<?php

use Vicomm\Vicomm;
use Vicomm\Exceptions\vicommErrorException;

$charge = Vicomm::charge();

$created = $charge->create($cardToken, $orderDetails, $userDetails);
$transactionId = $created->transaction->id;

try {
    $refund = $charge->refund($transactionId);
} catch (VicommErrorException $error) {
    // See the console output for complete information
    // Access to HTTP code from vicomm service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get status of refund
$status = $refund->status;
$detail = $refund->detail;

// Make a partial refund
$partialAmountToRefund = 10;
$refund = $charge->refund($transactionId, $partialAmountToRefund);

### Cash

Generate order

See the all available options in here

<?php

use Vicomm\Vicomm;
use Vicomm\Exceptions\VicommErrorException;

$cash = Vicomm::cash();

$carrierDetails = [
    'id' => 'oxxo', // Field required
    'extra_params' => [ // Depends of carrier, for oxxo is required
        'user' => [ // For oxxo is required
            'name' => "Juan",
            'last_name' => "Perez"
        ]
    ]
];

$userDetails = [
   'id' => "1", // Field required
   'email' => "[email protected]" // Field required
];

$orderDetails = [
    'dev_reference' => "XXXXXXX", // Field required 
    'amount' => 100, // Field required
    'expiration_days' => 1, // Field required
    'recurrent' => false, // Field required
    'description' => "XXXXXX" // Field required
];

try {
    $order = $cash->generateOrder($carrierDetails, 
    $userDetails, 
    $orderDetails);
} catch (VicommErrorException $error) {
    // See the console output for complete information
    // Access to HTTP code from vicomm service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get reference code
$referenceCode = $order->transaction->reference;
// Get expiration date
$expirationData = $order->transaction->expiration_date;
// Get order status
$status = $order->transaction->status;

Run unit tests

composer run test

gp-php-sdk's People

Contributors

foxnetorka avatar gpvicomm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.