Code Monkey home page Code Monkey logo

paymongo-php's Introduction

PayMongo PHP

PayMongo PHP library provides PHP applications an easy access to the PayMongo API. Explore various classes that can represent API resources on object instantiation. The goal of this library is simplify PayMongo integration with any PHP applications.

Check example.php see usage examples.

Pending Todos

  • Unit Tests
  • Code Cleanup and Improvements

Requirements

PHP 5.6.0 and later.

Composer

You can install the library via Composer. Run the following command:

composer require paymongo/paymongo-php

To use the bindings, use Composer's autoload:

require_once('vendor/autoload.php');

Manual Installation

If you prefer to manually install the library instead of using composer, you can download the latest release. Then, to use the bindings, include the initialize.php file.

require_once('/path/to/paymongo-php/initialize.php');

Dependencies

The bindings require the following extensions in order to work properly:

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that the required extensions are available.

Getting Started

Simple usage looks like:

$client = new \Paymongo\PaymongoClient('sk_test_BQokikJOvBiI2HlWgH4b2fQ2');
$paymentIntent = $client->paymentIntents->create([
    'amount' => 10000,
    'currency' => 'PHP',
    'payment_method_allowed' => ['card']
]);

echo $paymentIntent->id;

Handle errors

try {
    $client = new \Paymongo\PaymongoClient('sk_test_BQokikJOvBiI2HlWgH4b2fQ2');
    $paymentIntent = $client->paymentIntents->create([
        'amount' => 10000,
        'currency' => 'PHP',
        'payment_method_allowed' => ['card']
    ]);
} catch(\Paymongo\Exceptions\InvalidRequestException $e) {
   print "<pre>";
   print_r($e->getError());
   print "</pre>";
}

Verifying webhook signature

try {
    $payload = @file_get_contents('php://input');
    $signatureHeader = $_SERVER['HTTP_PAYMONGO_SIGNATURE'];
    $webhookSecretKey = 'your webhook secret key here';

    $event = $client->webhooks->constructEvent([
        'payload' => $payload,
        'signature_header' => $signatureHeader,
        'webhook_secret_key' => $webhookSecretKey
    ]);

    echo $event->id;
    echo $event->type;
    print "<pre>";
    print_r($event->resource);
    print "</pre>";
    die();

} catch (\Paymongo\Exceptions\SignatureVerificationException $e) {
    echo 'invalid signature';
}

To learn more about PayMongo's API, please check our developer documentation.

paymongo-php's People

Contributors

jaimehing avatar ronilo-penero avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

paymongo-php's Issues

Change Trait folder to ApiMethods

Instead of being specific to what type of files a folder may have (Traits), focus on the folder's functionality/feature. This what you call a feature-based folder structure. This type of folder structure guides the developer of what feature they might look at.

So far, the files under Traits folder look like the API methods of a resource (e.g. Token, Payment).

Actions to take:

  • Rename Traits folder to ApiMethods.
  • Change the namespace from Paymongo\Object to Paymongo\ApiMethods.

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.