Skip to content

About

Unofficial PayPay Open Payment API SDK for Go.

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Latest commit

 

History

80 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paypayopa-sdk-go

Japanese (日本語)

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 Reference Check codes Scan Vulnerabilities

Requirements

  • Go 1.24 or above

Installation

go get github.com/mythrnr/paypayopa-sdk-go

Design

Unlike REST-API-based SDKs, this SDK provides clients per integration scenario, so each client exposes only the methods relevant to that payment flow.

Quick Start

1. Create Credentials

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",
)

2. Create a Client and Call an API

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.

Supported Integrations

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

Environments

Use one of the following constants to specify the target environment.

Constant Environment
paypayopa.EnvProduction Production
paypayopa.EnvStaging Staging
paypayopa.EnvSandbox Sandbox (for development)

Error Handling

All API methods return (response, *ResultInfo, error).

  • error is non-nil when the request itself fails (e.g. network error, marshaling failure).
  • ResultInfo.Success() returns true when the HTTP status code is less than 400.
  • ResultInfo.Code and ResultInfo.Message contain 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)
}

Custom HTTP Client

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)

Webhooks

The SDK provides typed structs for webhook payloads. See the Webhook* types in the package documentation.

License

MIT

About

Unofficial PayPay Open Payment API SDK for Go.

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages