8d5f0693 by Yokihito Oki

first commit

0 parents
1 *.log
2 .DS_Store
3
4 /src/composer/vendor
...\ No newline at end of file ...\ No newline at end of file
1 # PayPay PHP Client のラッパークラス
2 https://github.com/paypay/paypayopa-sdk-php
3
4 ## Get Start
5 TBD
...\ No newline at end of file ...\ No newline at end of file
1 version: '3'
2
3 services:
4 php:
5 build:
6 context: .
7 dockerfile: ./php/Dockerfile
8 volumes:
9 - ./src:/var/www/html
10 environment:
11 PAYPAY_API_KEY: m_GnxuOq6AcO_4HOl
12 PAYPAY_API_SECRET: LSRwZZqMS8jxIa56JnkKNtW0GUSWJCSsKt2JwPDw
13 PAYPAY_MERCHANT_ID: 269480125409779712
14 # ports:
15 # - 8080:80
1 [Date]
2 date.timezone = "Asia/Tokyo"
3 [mbstring]
4 mbstring.internal_encoding = "UTF-8"
5 mbstring.language = "Japanese"
...\ No newline at end of file ...\ No newline at end of file
1 FROM php:7.3.9-apache
2 COPY php.ini /usr/local/etc/php/
3 RUN apt-get update && apt-get install -y \
4 git vim unzip \
5 && apt-get clean \
6 && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 // =============================================================================
3 // PayPayマネージャ
4 // =============================================================================
5 require_once(__DIR__ . '/composer/vendor/autoload.php');
6 include(__DIR__ . "/constants.php");
7
8 use PayPay\OpenPaymentAPI\Client;
9 use PayPay\OpenPaymentAPI\Models\CreateQrCodePayload;
10
11 class PayPayManager {
12
13 private $client = null;
14
15 // =======================================================
16 // コンストラクタ
17 // =======================================================
18 public function __construct ($api_key, $api_secret, $merchant_id) {
19 $this->$client = new Client([
20 'API_KEY' => $api_key,
21 'API_SECRET' => $api_secret,
22 'MERCHANT_ID' => $merchant_id
23 ], PAYPAY_IS_STAGING); //Set True for Production Environment. By Default this is set False for Sandbox Environment.
24 // ドキュメンのミス?
25 }
26
27 // =======================================================
28 // コード作成
29 // https://developer.paypay.ne.jp/products/docs/appinvoke#dynamic-qr-codeid
30 // アプリコールを使用して支払いを受け取るには、まずコードを作成する必要があります。
31 // $merchant_payment_id string(64) : 加盟店から提供された一意の支払い取引ID
32 // $price integer(11) : 支払金額
33 // $user_agent string(?) : トランザクションの発生元であるWebブラウザーのUser Agent
34 // =======================================================
35 public function create_code ($merchant_payment_id, $price, $user_agent) {
36 // setup payment object
37 $CQCPayload = new CreateQrCodePayload();
38
39 // Set merchant pay identifier
40 $CQCPayload->setMerchantPaymentId($merchant_payment_id);
41
42 // Log time of request
43 $CQCPayload->setRequestedAt();
44 // Indicate you want QR Code
45 $CQCPayload->setCodeType("ORDER_QR");
46
47 // TODO 明細情報
48 // Provide order details for invoicing
49 // $OrderItems = [];
50 // $OrderItems[] = (new OrderItem())
51 // ->setName('お食事代')
52 // ->setQuantity(1)
53 // ->setUnitPrice('amount' => 20, 'currency' => 'JPY']);
54 // $CQCPayload->setOrderItems($OrderItems);
55
56 // Save Cart totals
57 $amount = [
58 "amount" => $price,
59 "currency" => "JPY"
60 ];
61 $CQCPayload->setAmount($amount);
62 // Configure redirects
63 $CQCPayload->setRedirectType('WEB_LINK');
64 $CQCPayload->setRedirectUrl(PAYPAY_REDIRECT_URL);
65
66 // User Agent
67 $CQCPayload->setUserAgent($user_agent);
68
69 // Get data for QR code
70 $response = $this->$client->code->createQRCode($CQCPayload);
71
72 return $response;
73 }
74
75 // =======================================================
76 // コード削除
77 // https://developer.paypay.ne.jp/products/docs/appinvoke#delete-qr-codeid
78 // 生成したコードを削除したい場合こちらを利用ください。 このAPIを使用する理由として、次のことが考えられます。
79 // ユーザーが注文をキャンセルした場合
80 // ユーザーがPayPayアプリを開いて支払いを行わず、競合状態が発生しない目的でコードを削除する場合
81 // 処理を実施する場合には、以下のパラメーターを使用してリクエストしてください。
82 // $code_id string(?) : `Create a Code`メソッドのレスポンス値に含まれます。
83 // =======================================================
84 public function delete_code ($code_id) {
85 // Calling the method to delete a QR Code
86 $response = $this->$client->code->deleteQRCode($code_id);
87
88 return $response;
89 }
90
91 // =======================================================
92 // 決済情報取得
93 // https://developer.paypay.ne.jp/products/docs/appinvoke#fetch-qr-code
94 // 決済情報について参照をすることができます。このAPIを利用し決済が完了しているか確認してください。`create a code`の支払いプロセスは非同期で行われるため、このAPIをポーリング実装する必要があります。以下のパラメーターを設定することで、決済情報を参照することができます。
95 // $merchant_payment_id string(64) : 加盟店から提供された一意の支払い取引ID
96 // =======================================================
97 public function get_payment_details ($merchant_payment_id) {
98 // Calling the method to get payment details
99 $response = $this->$client->payment->getPaymentDetails($merchant_payment_id);
100
101 return $response;
102 }
103
104 // =======================================================
105 // 決済取り消し
106 // https://developer.paypay.ne.jp/products/docs/appinvoke#cancel-payment
107 // 決済をキャンセルしたい場合にこちらを利用ください。通常の決済フローでは基本的には、`Cancel a payment`を使いませんが以下の場合に利用ください。
108 // --Polling for Get Payment Details timeout, and you are uncertain of the status
109 // 注:`Cancel a payment`は、支払いが行われた翌日の00:14:59まで使用できます。 00:15 AM以降の場合、`Refund a payment`を呼び出して支払いを払い戻します。
110 // $merchant_payment_id string(64) : 加盟店から提供された一意の支払い取引ID
111 // =======================================================
112 public function cancel_payment ($merchant_payment_id) {
113 // Calling the method to cancel a Payment
114 $response = $this->$client->payment->cancelPayment($merchant_payment_id);
115
116 return $response;
117 }
118
119 // =======================================================
120 // 払い戻し処理
121 // https://developer.paypay.ne.jp/products/docs/appinvoke#refund-payment
122 // 決済が正常に完了しユーザーへの商品の提供後に、返品する場合に`Refund a payment`を使用ください。タイムアウトやシステム的なエラーが出て、決済処理を中止する場合には、`Cancel a payment`を活用ください。主要な項目を以下に記載しますので、以下のパラメーターを使用してリクエストしてください。
123 //
124 // $merchant_refund_id string(64) : 加盟店から提供された一意の払い戻し取引ID
125 // $payment_id string(64) : PayPayが決済後に発番する取引ID
126 // $amount integer(11) : 返金金額
127 // $reason string(255) : 返金理由
128 // =======================================================
129 public function refund_payment ($merchant_refund_id, $payment_id, $amount, $reason) {
130 // Creating the payload to refund a Payment, additional parameters can be added basis the API Documentation
131 $payload = new PaypaySdk/Payload();
132 $payload->set_merchant_refund_id('merchant_refund_id');
133 $payload->set_merchant_payment_id('paypay_payment_id');
134 $amount = [
135 "amount" => 1,
136 "currency" => "JPY"
137 ];
138 $payload->set_amount($amount);
139 $payload->set_reason("Reason for Refund");
140
141 // Calling the method to refund a Payment
142 $response = $this->$client->refund->refundPayment($payload);
143
144 return $response;
145 }
146
147 // =======================================================
148 // 払い戻しのステータスと詳細を取得する
149 // https://developer.paypay.ne.jp/products/docs/appinvoke#fetch-refund-payment
150 // 返金処理(`Refund a payment`)がタイムアウトをした場合には、このAPIを利用ください。処理を実施する場合には、以下のパラメーターを使用してリクエストしてください。
151 // $merchant_refund_id string(64) : 加盟店から提供された一意の返品取引ID
152 // =======================================================
153 public function fetch_refund_status_and_details ($merchant_refund_id) {
154 // Calling the method to get Refund Details
155 $response = $this->$client->refund->getRefundDetails($merchant_refund_id);
156
157 return $response;
158 }
159 }
160 ?>
1 {
2 "require": {
3 "paypayopa/php-sdk": "^1.0"
4 }
5 }
1 {
2 "_readme": [
3 "This file locks the dependencies of your project to a known state",
4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 "This file is @generated automatically"
6 ],
7 "content-hash": "52b3757d4b79086a90773895ea2ab80b",
8 "packages": [
9 {
10 "name": "firebase/php-jwt",
11 "version": "v5.2.0",
12 "source": {
13 "type": "git",
14 "url": "https://github.com/firebase/php-jwt.git",
15 "reference": "feb0e820b8436873675fd3aca04f3728eb2185cb"
16 },
17 "dist": {
18 "type": "zip",
19 "url": "https://api.github.com/repos/firebase/php-jwt/zipball/feb0e820b8436873675fd3aca04f3728eb2185cb",
20 "reference": "feb0e820b8436873675fd3aca04f3728eb2185cb",
21 "shasum": ""
22 },
23 "require": {
24 "php": ">=5.3.0"
25 },
26 "require-dev": {
27 "phpunit/phpunit": ">=4.8 <=9"
28 },
29 "type": "library",
30 "autoload": {
31 "psr-4": {
32 "Firebase\\JWT\\": "src"
33 }
34 },
35 "notification-url": "https://packagist.org/downloads/",
36 "license": [
37 "BSD-3-Clause"
38 ],
39 "authors": [
40 {
41 "name": "Neuman Vong",
42 "email": "neuman+pear@twilio.com",
43 "role": "Developer"
44 },
45 {
46 "name": "Anant Narayanan",
47 "email": "anant@php.net",
48 "role": "Developer"
49 }
50 ],
51 "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.",
52 "homepage": "https://github.com/firebase/php-jwt",
53 "keywords": [
54 "jwt",
55 "php"
56 ],
57 "time": "2020-03-25T18:49:23+00:00"
58 },
59 {
60 "name": "paypayopa/php-sdk",
61 "version": "1.0.0",
62 "source": {
63 "type": "git",
64 "url": "https://github.com/paypay/paypayopa-sdk-php.git",
65 "reference": "fd56ebfcdf1128b9dc082bc5e773312a38561bef"
66 },
67 "dist": {
68 "type": "zip",
69 "url": "https://api.github.com/repos/paypay/paypayopa-sdk-php/zipball/fd56ebfcdf1128b9dc082bc5e773312a38561bef",
70 "reference": "fd56ebfcdf1128b9dc082bc5e773312a38561bef",
71 "shasum": ""
72 },
73 "require": {
74 "firebase/php-jwt": "^5.2",
75 "php": ">=7.0.0"
76 },
77 "require-dev": {
78 "friendsofphp/php-cs-fixer": "^2.16",
79 "phpstan/phpstan": "^0.12.33",
80 "phpunit/phpunit": "^9"
81 },
82 "type": "library",
83 "autoload": {
84 "psr-4": {
85 "PayPay\\OpenPaymentAPI\\": "src/"
86 }
87 },
88 "notification-url": "https://packagist.org/downloads/",
89 "license": [
90 "Apache-2.0"
91 ],
92 "authors": [
93 {
94 "name": "PayPay Open Source Development Team",
95 "email": "opensource@paypay-corp.co.jp"
96 }
97 ],
98 "description": "PHP SDK for PayPay Open Payment API",
99 "keywords": [
100 "japan",
101 "opa",
102 "payment",
103 "paypay",
104 "qr",
105 "qrcode"
106 ],
107 "time": "2020-07-29T02:49:01+00:00"
108 }
109 ],
110 "packages-dev": [],
111 "aliases": [],
112 "minimum-stability": "stable",
113 "stability-flags": [],
114 "prefer-stable": false,
115 "prefer-lowest": false,
116 "platform": [],
117 "platform-dev": [],
118 "plugin-api-version": "1.1.0"
119 }
1 <?php
2 define('PAYPAY_IS_STAGING', true);
3 define('PAYPAY_REDIRECT_URL', 'http://localhost:3000/user/paypay_complete/');
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 include(__DIR__ . "/PayPayManager.php");
3
4 try {
5 $paypay = new PayPayManager('m_GnxuOq6AcO_4HOl', 'LSRwZZqMS8jxIa56JnkKNtW0GUSWJCSsKt2JwPDw', 269480125409779712);
6 error_log(print_r($paypay, true), 3, '/var/www/html/debug.log');
7
8 // コード作成
9 // $response = $paypay->create_code('1', 100, 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1');
10 // $merchant_payment_id = NULL;
11 // $code_id = NULL;
12 // $url = '';
13 // if ($response['resultInfo']['code'] == 'SUCCESS') {
14 // $url = $response['data']['url'];
15 // $merchant_payment_id = $response['data']['merchantPaymentId'];
16 // $code_id = $response['data']['codeId'];
17 // }
18 // error_log(print_r($response, true), 3, '/var/www/html/debug.log');
19
20 // // 決済情報取得
21 // $response = $paypay->get_payment_details(1);
22 // error_log(print_r($response, true), 3, '/var/www/html/debug.log');
23
24 // コード削除
25 // $response = $paypay->delete_code('04-rNtyNkmqva9KNakh');
26 // error_log(print_r($response, true), 3, '/var/www/html/debug.log');
27
28 // 決済取り消し
29 // $response = $paypay->cancel_payment(1);
30 // error_log(print_r($response, true), 3, '/var/www/html/debug.log');
31
32 } catch (Exception $e) {
33 }
...\ No newline at end of file ...\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!