Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[PHP] Payoneer 결제 API

2017-07-31 by 편리

Payoneer의 예치금을 이용해 결제를 처리할 수 있는 API이다. Payoneer 파트너사에 가입하고 지불처리하는 것이 주된 기능이다.

<?php
/**
 * @Author: Seongho Jang
 * @Date:   2017-07-21
 * @Last Modified by:   Seongho Jang
 * @Last Modified time: 2017-07-21 17:33:27
*/

class Payoneer
{
    const SANDBOX_API_URL    = 'https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx';
    const PRODUCTION_API_URL = 'https://api.payoneer.com/payouts/HttpAPI/API.aspx';

    public $apiEndpoint;    
    public $apiUser;    
    public $apiPassword;
    public $partnerId;
    public $sandbox = true;
    
    private $response;
    private $params;
    
    function __construct($apiUser, $apiPassword, $partnerId, $sandbox = true) {
        $this->sandbox = $sandbox;
        if($sandbox == true){
            $this->apiEndpoint = static::SANDBOX_API_URL;    
        }
        else{
            $this->apiEndpoint = static::PRODUCTION_API_URL;
        }
        
        $this->apiUser = $apiUser;
        $this->apiPassword = $apiPassword;
        $this->partnerId = $partnerId;
    }

    public function getBasicParameters() {
        return ['p1' => $this->apiUser, 'p2' => $this->apiPassword, 'p3' => $this->partnerId];
    }

    public function getToken($request)
    {
        $this->call('GetToken', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function getTokenXML($request)
    {
        $this->call('GetTokenXML', $request);
        $response = $this->response;
        return $this->getData('Token');
    }

    public function getApiStatus($item='')
    {
        $this->call('Echo');
        
        return $this->getData($item);
    }

    public function getVersion()
    {
        $this->call('GetVersion');
        $response = $this->response;
        return $this->getData('Version');
    }

    public function chargeAccount($request)
    {
        $this->call('ChargeAccount', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function cancelChargeAccount($request)
    {
        $this->call('CancelChargeAccount', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function getPaymentStatus($request)
    {
        $this->call('GetPaymentStatus', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function convertArray($object)
    {
        return json_decode( json_encode( $object ), 1 );
    }

    public function getData($key='')
    {
        $xml = simplexml_load_string($this->response);

        $data = $this->convertArray($xml);

        if($key)
            return $data[$key];
        else
            return $data;
    }

    public function call($methodName, $request=null)
    {
        $this->params = $this->getBasicParameters();

        if($request && is_array($request))
            $this->params = array_merge($this->params, $request);

        $url = $this->apiEndpoint.'?mname='.$methodName;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->params);
        
        $this->response = curl_exec($ch);
        $err = curl_error($ch);

        curl_close($ch);
    }
}

위 API를 이용해 Sign-Up 기능을 구현한 코드는 아래오 같다.

<?php
require_once('./Payoneer.Api.php');

$payee_id = trim($_POST['payee_id']);

$payoneer = new Payoneer(PAYONEER_USERNAME, PAYONEER_API_PASSWORD, PAYONEER_PARTNER_ID, PAYONEER_SANDBOX);

$request = array(
    'p4'  => $payee_id,
    'p6'  => 'http://example.com/payoneer/payoneer.php',
    'p8'  => 5,
    'p10' => 'True'
);

$result = $payoneer->getToken($request);

$error = '';
$token = '';

if(isset($result['Token'])) {
    $token = $result['Token'];
} else {
    $error = '['.$result['Code'].'] '.$result['Description'];
}

die(json_encode(array('error' => $error, 'token' => $token)));

 

Post navigation

Previous Post:

[PHP] xml 포맷의 데이터를 배열(Array)로 변환

Next Post:

아마존마케팅툴(amazonmarketingtool.com) 개발

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes