Giter Site home page Giter Site logo

go-paypal-classic's Introduction

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
    }
}

go-paypal-classic's People

Contributors

evalphobia avatar tamaki0506 avatar

Stargazers

Florian Schlachter avatar Alfred Hall avatar Jiang Le avatar Simon Waldherr avatar Christian Muehlhaeuser avatar Matt Mc avatar Marcelle von Wendland avatar Thomas Adam avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.