A memo written by Mr. Kagawa, a LINE Pay teacher, to help you understand and use the SDK created by @ sumihiro3. https://github.com/sumihiro3/line-pay-sdk-python/tree/master/examples
I made a starter for one-time general payment only, so please use here.
The SDK is a package of programs, APIs, sample code, etc. so that you can develop applications with less effort. The SDK allows developers to implement new features in their applications without having to understand the detailed mechanics of the technology that enables them.
Quote: https://dev.classmethod.jp/articles/devio-cafe-line/
Quote: https://dev.classmethod.jp/articles/line-pay-v3-lambda/
It's a little confusing, but SP is a service provider and we are a business operator.
① Have Pay issue a payment URL using the Request API ② Ask the user to throw the URL and tap it to approve it on the payment screen in the example. ③ Then, we will receive an approved notification from our business operator (app and system), which is the SP, so we will complete the payment using the Confirm API.
Normally, this will confirm sales, and we don't have to use the Capture API. However, there seems to be a case where you want to take one step between the completion of payment and the confirmation of sales, in which case you have to perform the sales confirmation process yourself using the Capture API as shown below.
If "options.payment.capture" of Request API is set to false, the settlement and sales confirmation will be separated, and the payment status will remain in the sales confirmation waiting (authorization) state even if the payment is completed. To confirm the sales, you need to call the Capture API to confirm the sales.
request_options = {
//abridgement
"options": {
"payment": {
"capture": False
}
},
//abridgement
response = api.request(request_options)
This is the basic payment flow of LINE Pay API v3, but from the user's point of view, we are beginner engineers because there are only three steps: "Pay with LINE Pay" → "Go to the payment screen" → "Press the payment button". I think it's hard to imagine that the above processing is done behind the scenes. It's a crazy SDK, so I think it's okay to use it even if you don't know this area.
--As a prerequisite, the Python version of your PC should be 3.6 or higher. --If you do not have a LINE Pay member store ID or do not make an actual payment, please obtain a member store account in the Sandbox environment.
However, if you do it in the sandbox, the behavior of Pay will be different from the actual behavior, and the display of automatic payment (subscription) will be the same as general payment, so it will be complicated. I wonder if LINE will create an account that can be tested with the same behavior.
Even if you log in to the member store MyPage with your Sandbox account, no transaction history will be recorded on that screen. After logging in, click the Sandbox
link in the upper right to see the transaction history settled in Sandbox (the first screen seems to have no use other than getting the interlocking key ...).
First, clone the GitHub repository or Download and unzip it.
Go to this directory in your terminal
$ cd ine-pay-sdk-python-master
Install the required libraries with pip install
$ pip install -r requirements.txt
Create a .env
file by copying the .env.sample
file
$ cp ./.env.sample ./.env
Make port 8000 accessible by external URL with ngrok
$ ngrok http 8000
Edit the .env
file with any editor such as VSCode, Atom, vim, emacs
Enter the domain issued by ngrok and the Channes_ID and Channel Secret Key that can be confirmed from the payment interlocking management> interlocking key of LINE Pay member store MyPage.
HOST_NAME=xxxxx.ngrok.io
LINE_PAY_CHANNEL_ID=YOUR_LINE_PAY_CHANNEL_ID
LINE_PAY_CHANNEL_SECRET=YOUR_LINE_PAY_CHANNEL_SECRET
基本的にこのSDKは試したい決済流れの.py
ファイルをRunさせて、xxxxx.ngrok.io/request
にアクセスすることでその流れを試せる作りになっているようだ。
$ python request-confirm-refund.py
If you access https://xxxxx.ngrok.io/request
in this state
When you press paymentUrl
(because it is a sandbox), you will be taken to the screen below, so log in to LINE (when you try to access the above URL on mobile or try to make a payment by scanning the QR code, it fails for some reason ...).
The sandbox mock payment screen opens, so press PAY NOW
When the payment is completed, you will be redirected to the screen that displays the payment result.
This time it is a py file that you can try refunding, so if you press the REFUND
link at the bottom, you can process the refund and you will be redirected to the next screen.
The transaction breakdown on the Sandbox screen of the member store MyPage at this time is as follows, and the upper No. 1 is recorded as the settlement process and the lower No. 2 is recorded as the settlement cancellation process.
By setting options.payment.capture in request_options to False, you can dare to wait for sales confirmation (authorization) after payment, and later try sales confirmation (capture) using Capture API ʻauthorizations-capture.py` file Run.
authorizations-capture.py
"options": {
"payment": {
"capture": False
}
},
$ python authorizations-capture.py
Similarly, if you access https://xxxxx.ngrok.io/request
and make a payment, you will be redirected to the screen with the capture link.
The transaction breakdown of the member store MyPage at this time is as follows.
Transaction breakdown after settlement ↓
Transaction breakdown after capture ↓
The sales confirmation process should be possible from this screen as well, but for some reason there is no sales confirmation button when using this SDK. Is it because it's a sandbox?
Checkout
Checkout is an API that allows you to make payments including the shipping address and shipping fee when making payments with EC etc., but this API cannot be used in the Sandbox environment, and official member stores are also reviewing its use. So it seems that this SDK does not have a py file to try.
$ python request-confirm-pre_approved.py
If you access https://xxxxx.ngrok.io/request
in the same way and make a payment, you can get the RegKey for automatic payment after the payment. It seems that the first payment and the acquisition of RegKey are performed at the same time as using LINE Pay (Sandbox does not reproduce the check in the original automatic payment flow ...).
You can make automatic payments using RegKey and the Pay Preapproved API by clicking the link below. However, the transaction breakdown of the member store MyPage does not record the transaction by automatic settlement. Is this also a sandbox?
The flow of formal LINE Pay automatic payment is as follows. https://youtu.be/KdQLm88nl2Q
xxx.py
@app.route("/request", methods=['GET'])
def pay_request():
#abridgement
return render_template("request.html", result=response)
https://dev.classmethod.jp/articles/linepay-regkey/
https://qiita.com/sotozaki/items/e178f5ec3c34aa7b1b17
--RegKey is valid for 180 days --There is an API to check if RegKey is valid, but there is no way to know the expiration date --Users can expire from the settings screen --In the sandbox environment, the expiration date is set to 1 day
The user's expire is probably here
Launch LINE Pay from the LINE app wallet (launch as a LIFF app) Press automatic payment at the bottom If you subscribe in the production environment, you can manage it here. Note that no Reg Key in Sandbox is displayed.Recommended Posts