Code Monkey home page Code Monkey logo

sdk-php's Introduction

Contributors Forks Stargazers Issues Packagist PHP Version MIT License Workflow


Smartpay PHP Library

The Smartpay PHP library offers easy access to Smartpay API from applications written in PHP.

Documentation

Requirements

  • PHP 5.6+
  • Smartpay API keys & secrets. You can find your credential at the settings > credentials page on your dashboard.

Installation

Install Composer

Composer is a dependency manager for PHP projects.

Download Composer from their website: https://getcomposer.org/download/

If you are using macos to develop with homebrew, you can use the command to install Composer:

brew install composer

Install package to your repository:

composer install smartpay-co/sdk-php

Usage

The package needs to be configured with your own API keys, you can find them on your dashboard.

$api = new \Smartpay\Api('<YOUR_SECRET_KEY>', '<YOUR_PUBLIC_KEY>')

Create Checkout session

You can find the description and requirement for request payload in API Document.

$payload = [
  'items' => [
    [
      'name' => 'オリジナルス STAN SMITH',
      'amount' => 1000,
      'currency' => 'JPY',
      'quantity' => 1,
    ],
    [
      'currency' => 'JPY',
      'amount' => 500,
      'name' => 'Merchant special discount',
      'kind' => 'discount'
    ],
    [
      'currency' => 'JPY',
      'amount' => 100,
      'name' => 'explicit taxes',
      'kind' => 'tax'
    ]
  ],
  'customerInfo' => [
    'accountAge' => 20,
    'email' => '[email protected]',
    'firstName' => '田中',
    'lastName' => '太郎',
    'firstNameKana' => 'たなか',
    'lastNameKana' => 'たろう',
    'address' => [
      'line1' => '北青山 3-6-7',
      'line2' => '青山パラシオタワー 11階',
      'subLocality' => '',
      'locality' => '港区',
      'administrativeArea' => '東京都',
      'postalCode' => '107-0061',
      'country' => 'JP',
    ],
    'dateOfBirth' => '1985-06-30',
    'gender' => 'male',
  ],
  'shippingInfo' => [
    'line1' => '北青山 3-6-7',
    'line2' => '青山パラシオタワー 11階',
    'subLocality' => '',
    'locality' => '港区',
    'administrativeArea' => '東京都',
    'postalCode' => '107-0061',
    'country' => 'JP',
  ],
  'reference' => 'order_ref_1234567',
  'successUrl' => 'https://docs.smartpay.co/example-pages/checkout-successful',
  'cancelUrl' => 'https://docs.smartpay.co/example-pages/checkout-canceled'
];

Create a checkout session by using checkoutSession method with your request payload.

$session = $api->checkoutSession($payload);

Then, you can redirect your customer to the session url by calling redirectUrl method:

$session->redirectUrl()

Test

Install dependencies

composer i

Run test in the folder

./vendor/bin/phpunit tests

License

The package is available as open source under the terms of the MIT License.

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.