Skip to content

evalphobia/go-paypal-classic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-paypal-classic

GoDoc Apache 2.0 License Release Build Status Codecov Coverage Go Report Card Downloads

go-paypal-classic is library for PayPal Classic API

Current Supported API list

Quick Usage

SetExpressCheckout

import (
    "os"

    "github.com/evalphobia/go-paypal-classic/config"
    "github.com/evalphobia/go-paypal-classic/client/merchant"
)

func main() {
    user := os.Getenv("PAYPAL_USER")
    pwd := os.Getenv("PAYPAL_PWD")
    signature := os.Getenv("PAYPAL_SIGNATURE")
    conf := config.New(user, pwd, signature)

    mer := merchant.New(conf)
    sec := &merchant.SetExpressCheckout{
        TotalAmount: 100.00,
        ReturnURL:   "http://localhost/confirm",
        CancelURL:   "http://localhost/cancel",
        Currency:    merchant.CurrencyUSD,
    }

    resp, err := sec.Do(mer)
    if err != nil {
        panic("error occured on SetExpressCheckout api request")
    }

    if resp.IsSuccess() {
        resp.RedirectURL()
        // => https://www.paypal.com/webscr?cmd=_express-checkout&token=<TOKEN>
    }
}

GetExpressCheckoutDetails

import (
    "github.com/evalphobia/go-paypal-classic/client/merchant"
)

func main() {
    gecd = &merchant.GetExpressCheckoutDetails{
        Token: "EC-XXXXXXXXXXXX",
    }

    resp, err := gecd.Do(mer)
    if err != nil {
        panic("error occured on GetExpressCheckoutDetails api request")
    }

    if resp.IsSuccess() {
        // verified or unverified
        resp.IsPayerVerified()
    }
}

DoExpressCheckoutPayment

import (
    "github.com/evalphobia/go-paypal-classic/client/merchant"
)

func main() {
    decp = &merchant.DoExpressCheckoutPayment{
        Token:       "EC-XXXXXXXXXXXX",
        PayerID:     "XXX",
        TotalAmount: 100.0,
        Currency:    merchant.CurrencyUSD,
    }

    resp, err := decp.Do(mer)
    if err != nil {
        panic("error occured on DoExpressCheckoutPayment api request")
    }

    if resp.IsSuccess() {
        // payment request is success or not
        resp.IsPaymentSuccess()
    }
}

DoExpressCheckoutPayment

import (
    "github.com/evalphobia/go-paypal-classic/client/merchant"
)

func main() {
    decp = &merchant.CreateRecurringPaymentsProfile{
        Token:       "EC-XXXXXXXXXXXX",
        PayerID:     "XXX",
        TotalAmount: 100.0,
        Currency:    merchant.CurrencyUSD,
        Description: "this is recurring payment",
    }
    decp.SetPeriodAsMonth(3) // once every three months
    decp.SetBillingStartDateFromNow() // the 1st billing starts three month later

    resp, err := decp.Do(mer)
    if err != nil {
        panic("error occured on CreateRecurringPaymentsProfile api request")
    }

    if resp.IsSuccess() {
        // created recurring profile id
        // resp.ProfileID
    }
}

GetRecurringPaymentsProfileDetails

import (
    "github.com/evalphobia/go-paypal-classic/client/merchant"
)

func main() {
    grpp = &merchant.GetRecurringPaymentsProfileDetails{
        ProfileID: "I-000000000000",
    }
    resp, err := grpp.Do(mer)
    if err != nil {
        panic("error occured on GetRecurringPaymentsProfileDetails api request")
    }

    if resp.IsSuccess() {
        // recurring payment status
        // resp.Status
    }
}

ManageRecurringPaymentsProfileStatus

import (
    "github.com/evalphobia/go-paypal-classic/client/merchant"
)

func main() {
    mrpp := &merchant.ManageRecurringPaymentsProfileStatus{
        ProfileID: "I-000000000000",
    }
    svc.SetAsCancel("You must pay my bill!")

    resp, err := mrpp.Do(mer)
    if err != nil {
        panic("error occured on ManageRecurringPaymentsProfileStatus api request")
    }

    if resp.IsSuccess() {
        // profile id will be present when success
        // resp.ProfileID
    }
}

TransactionSearch

import (
    "time"

    "github.com/evalphobia/go-paypal-classic/client/transaction"
)

func main() {
    ts = &transaction.TransactionSearch{
        StartDate: time.Now(),
        ProfileID: "I-000000000000",
    }
    resp, err := ts.Do(cli)
    if err != nil {
        panic("error occured on TransactionSearch api request")
    }

    if resp.IsSuccess() {
        // transaction list
        // resp.Items
    }
}

About

PayPal Classic API library for golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages