Skip to content

Commit

Permalink
楽天Pay confirmOrder実装
Browse files Browse the repository at this point in the history
  • Loading branch information
YoheiKokubo committed Sep 20, 2018
1 parent b35853f commit ddd6a2d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions define.php
Expand Up @@ -22,8 +22,11 @@
define("RMS_API_CATEGORY_INSERT", 'https://api.rms.rakuten.co.jp/es/1.0/categoryapi/shop/category/insert');
define("RMS_API_CATEGORY_UPDATE", 'https://api.rms.rakuten.co.jp/es/1.0/categoryapi/shop/category/update');
define("RMS_API_CATEGORY_DELETE", 'https://api.rms.rakuten.co.jp/es/1.0/categoryapi/shop/category/delete');

// 楽天ペイAPI エンドポイント
define("RMS_API_RAKUTEN_PAY_GET_ORDER", 'https://api.rms.rakuten.co.jp/es/2.0/order/getOrder/');
define("RMS_API_RAKUTEN_PAY_SEARCH_ORDER", 'https://api.rms.rakuten.co.jp/es/2.0/order/searchOrder/');
define("RMS_API_RAKUTEN_PAY_CONFIRM_ORDER", 'https://api.rms.rakuten.co.jp/es/2.0/order/confirmOrder/');

// 商品登録(ItemAPI)設定関連
define("RMS_CATALOG_EXCEPTION_REASON_NO_JAN", 5);
Expand Down
89 changes: 89 additions & 0 deletions rakutenPayConfirmOrder.php
@@ -0,0 +1,89 @@
<?php

require_once('config.php');
require_once('util.php');

$orderNumber = '123456-20180101-00111801';
if($_GET[num]) {
$orderNumber = $_GET[num];
}

$orderNumberList = array($orderNumber);



list($httpStatusCode, $response) = confirmOrder($orderNumberList);

/***
* RakutenPayOrderAPI confirmOrder APIを使って、楽天ペイ注文の「注文情報の取得」を行うことができます。
* サンプルレスポンスは下記
* */
function confirmOrder($orderNumberList) {
$authkey = base64_encode(RMS_SERVICE_SECRET . ':' . RMS_LICENSE_KEY);
$header = array(
'Content-Type: application/json; charset=utf-8',
"Authorization: ESA {$authkey}",
);

$requestJson = json_encode([
'orderNumberList' => $orderNumberList
]);

$url = RMS_API_RAKUTEN_PAY_CONFIRM_ORDER;

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POSTFIELDS, $requestJson);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //返り値を 文字列で返します

$response = curl_exec($ch);
if(curl_error($ch)){
$response = curl_error($ch);
}

$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

$response = json_decode( $response, true );

curl_close($ch);
return array($httpStatusCode, $response);
}

?>

<!DOCTYPE html>
<html>
<head>
<title>confirmOrder | RakutenPayOrderAPI</title>
<meta charset="UTF-8">
<style>
pre,code {
width:100%;
overflow: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<div style="width:100%;">
<h1>レスポンス結果</h1>
<h2>HTTP Status code</h2>
<pre>
<?php echo $httpStatusCode; ?>
</pre>
<h2>生レスポンス</h2>
<pre>
<?php
echo print_r($response, true);
?>
</pre>
</div>
</body>
</html>

0 comments on commit ddd6a2d

Please sign in to comment.