Coder Social home page Coder Social logo

credo-payments's Introduction

Credo Payments

This package is for communicating with credocentral.com and credodemo.com API

Getting Started

Install the package using composer.

Run composer require ezeasorekene/credo-payments

Define your api keys

Define your $apiKeys variable as an array with the public and private keys. You should get the keys from environment variables. Also define CREDO_MODE environment key with parameters DEMO | LIVE

    $apiKeys = [
        'publicKey' => getenv("CREDO_MODE") == 'LIVE' ? getenv("CREDO_LIVE_PUBLIC_KEY") : getenv("CREDO_TEST_PUBLIC_KEY"),
        'secretKey' => getenv("CREDO_MODE") == 'LIVE' ? getenv("CREDO_LIVE_SECRET_KEY") : getenv("CREDO_TEST_SECRET_KEY"),
    ];

Instantiating Transaction

   $credo = new CredoPay( $apiKeys, getenv("CREDO_MODE") );

Set data to post using array. Please note that the serviceCode is an optional field. It is used when you want to split payments between different accounts

        $credodata = [
            'reference' => uniqid(),
            'amount' => 20000, //in kobo
            'bearer' => 0,
            'callbackUrl' => 'http://example.com/callback/credo',
            'currency' => 'NGN',
            'customerFirstName' => 'Credo',
            'customerLastName' => 'Package',
            'customerPhoneNumber' => '234080111111111',
            'email' => '[email protected]',
            'channels' => array('card', 'bank'),
            'serviceCode' => 'XXXXXXXXXXX',
            "metadata" => [
                "customFields" => [
                    [
                        'display_name' => 'Custom Field Display 1',
                        'variable_name' => 'Custom Field Variable 1',
                        'value' => 'Custom Field Value 1'
                    ]
                ]
            ],
        ];

Response is a JSON encoded object. So to decode, perform a json_decode

    $response = json_decode($credo->initialize($credodata));

Verifying Transaction

    $credo = new CredoPay( $apiKeys, getenv("CREDO_MODE") );
    $verify = json_decode($credo->verify($reference));

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.