In July 2020, "PayPay for Developers," a tool for developers that can introduce PayPay to payments for EC sites and apps operated by the company, was released.
I would like to try it until the payment is completed in the sandbox environment.
First, register with PayPay for Developers. https://developer.paypay.ne.jp/
Once registered, you will have your API key and test user.
This time, I will work on CentOS 7 with Python 3.6 and pip 3.6 installed.
pip3.6 install paypayopa
The PayPay OPA SDK version 0.6.0 has been installed.
We will issue a QR code for payment using the PayPay app or a web payment implementation method that allows payment on a web page. Request a unique value for "merchant_payment_id".
import paypayopa
client = paypayopa.Client(auth=(API_KEY, API_SECRET), production_mode=False)
request = {
"merchantPaymentId": "merchant_payment_id",
"codeType": "ORDER_QR",
"redirectUrl": "http://www.example.com/success",
"redirectType":"WEB_LINK",
"orderDescription":"Example - Mune Cake shop",
"orderItems": [{
"name": "Moon cake",
"category": "pasteries",
"quantity": 1,
"productId": "67678",
"unitPrice": {
"amount": 1,
"currency": "JPY"
}
}],
"amount": {
"amount": 1,
"currency": "JPY"
},
}
response = client.Code.create_qr_code(request)
print(response)
A response will be returned.
{
"resultInfo": {
"code": "string",
"message": "string",
"codeId": "string"
},
"data": {
"codeId": "string",
"url": "string",
:
abridgement
:
"redirectUrl": "string",
"redirectType": "WEB_LINK",
:
abridgement
:
}
}
When you access the response url with your smartphone, you will be asked if you want to start PayPay.
The payment is now complete.
Please refer to here for how to log in as a test user of the PayPay app. https://paypay.ne.jp/developers-faq/sandbox_environment/post-43/
Use Get Payment Details to see if your payment is complete. Make a request using the "merchant_payment_id" mentioned earlier.
import paypayopa
client = paypayopa.Client(auth=(API_KEY, API_SECRET), production_mode=False)
response = client.Payment.get_payment_details("merchant_payment_id")
print(response)
Payment is complete when "SUCCESS" is returned in the response code.
{
"resultInfo": {
"code": "string",
"message": "string",
"codeId": "string"
}
}
Ultimately, I would like to be able to select PayPay as the payment method on the EC site.
It is such an image.
To use it in production, you need to apply for a member store.
You can try the sandbox environment by registering with PayPay for Developers, so if you are interested, please try it.
Recommended Posts