Warning: This SDK is unofficial. For the official documentation, see https://developer.paypay.ne.jp.
Package paypayopa provides a Go SDK for the
PayPay Open Payment API.
- Go 1.24 or above
go get github.com/mythrnr/paypayopa-sdk-goUnlike REST-API-based SDKs, this SDK provides clients per integration scenario, so each client exposes only the methods relevant to that payment flow.
Use paypayopa.NewCredentials with the API key generated on the
PayPay developer page.
creds := paypayopa.NewCredentials(
paypayopa.EnvSandbox,
"YOUR_API_KEY",
"YOUR_API_KEY_SECRET",
"YOUR_MERCHANT_ID",
)The following example creates a QR code for Web Payment and then deletes it.
package main
import (
"context"
"log"
"github.com/google/uuid"
"github.com/mythrnr/paypayopa-sdk-go"
)
func main() {
creds := paypayopa.NewCredentials(
paypayopa.EnvSandbox,
"YOUR_API_KEY",
"YOUR_API_KEY_SECRET",
"YOUR_MERCHANT_ID",
)
wp := paypayopa.NewWebPayment(creds)
ctx := context.Background()
res, info, err := wp.CreateQRCode(ctx, &paypayopa.CreateQRCodePayload{
MerchantPaymentID: uuid.NewString(),
Amount: &paypayopa.MoneyAmount{
Amount: 1000,
Currency: paypayopa.CurrencyJPY,
},
CodeType: paypayopa.CodeTypeOrderQR,
RedirectURL: "https://example.com/callback",
RedirectType: paypayopa.RedirectTypeWebLink,
})
if err != nil {
log.Fatalf("request failed: %+v", err)
}
if !info.Success() {
log.Fatalf("API error: %s (code: %s)", info.Message, info.Code)
}
log.Printf("QR Code URL: %s", res.URL)
if _, err = wp.DeleteQRCode(ctx, res.CodeID); err != nil {
log.Fatalf("delete failed: %+v", err)
}
}For a more complete example application, see paypay-sample-ecommerce-backend-go.
| Integration | Document | Client |
|---|---|---|
| Web Payment | Doc | NewWebPayment |
| Native Payment | Doc | NewNativePayment |
| Dynamic QR | Doc | NewDynamicQR |
| App Invoke | Doc | NewAppInvoke |
| Continuous Payment | Doc | NewContinuousPayment |
| PreAuth & Capture | Doc | NewPreAuthCapture |
| Request Money | Doc | NewRequestMoney |
Use one of the following constants to specify the target environment.
| Constant | Environment |
|---|---|
paypayopa.EnvProduction |
Production |
paypayopa.EnvStaging |
Staging |
paypayopa.EnvSandbox |
Sandbox (for development) |
All API methods return (response, *ResultInfo, error).
erroris non-nil when the request itself fails (e.g. network error, marshaling failure).ResultInfo.Success()returnstruewhen the HTTP status code is less than 400.ResultInfo.CodeandResultInfo.Messagecontain API-level error details.
res, info, err := client.CreateQRCode(ctx, payload)
if err != nil {
// Transport or marshaling error
log.Fatal(err)
}
if !info.Success() {
// API returned an error response
log.Printf("code=%s message=%s", info.Code, info.Message)
}Each client constructor has a WithHTTPClient variant that accepts
a pre-configured *http.Client. This is useful for setting custom
timeouts, proxies, or transport-level configurations.
httpClient := &http.Client{
Timeout: 30 * time.Second,
}
wp := paypayopa.NewWebPaymentWithHTTPClient(creds, httpClient)The SDK provides typed structs for webhook payloads.
See the Webhook* types in the
package documentation.