Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ _testmain.go
*.exe
*.test
*.prof
*.project
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 fundary
Copyright (c) 2015 Lee Benson.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Payment REST API Go client

[![Coverage Status](https://coveralls.io/repos/fundary/paypal/badge.png)](https://coveralls.io/r/fundary/paypal) [![GoDoc](https://godoc.org/github.com/fundary/paypal?status.svg)](https://godoc.org/github.com/fundary/paypal)
[![GoDoc](https://godoc.org/github.com/leebenson/paypal?status.svg)](https://godoc.org/github.com/leebenson/paypal)

This is a client for the Paypal REST API ([https://developer.paypal.com/webapps/developer/docs/api/](https://developer.paypal.com/webapps/developer/docs/api/)

Expand All @@ -13,7 +12,7 @@ This is a client for the Paypal REST API ([https://developer.paypal.com/webapps/
## Usage

```bash
go get github.com/fundary/paypal
go get github.com/leebenson/paypal
```

Import into your app and start using it:
Expand All @@ -26,18 +25,18 @@ import (
"log"
"os"

"github.com/fundary/paypal"
"github.com/leebenson/paypal"
)

func main() {
clientID := os.Getenv("PAYPAL_CLIENTID")
if clientID == "" {
panic("Paypal clientID is missing")
panic("PayPal clientID is missing")
}

secret := os.Getenv("PAYPAL_SECRET")
if secret == "" {
panic("Paypal secret is missing")
panic("PayPal secret is missing")
}

client := paypal.NewClient(clientID, secret, paypal.APIBaseLive)
Expand Down
23 changes: 13 additions & 10 deletions paymenttype.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type (

// Authorization maps to the authorization object
Authorization struct {
Id int64 `json:"-"`
Amount *Amount `json:"amount,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
Expand All @@ -147,6 +148,7 @@ type (

// Capture maps to the capture object
Capture struct {
Id int64 `json:"-"`
Amount *Amount `json:"amount,omitempty"`
IsFinalCapture bool `json:"is_final_capture"`
CreateTime *time.Time `json:"create_time,omitempty"`
Expand All @@ -159,6 +161,7 @@ type (

// Details maps to the details object
Details struct {
Id int64 `json:"-"`
Shipping string `json:"shipping,omitempty"`
Subtotal string `json:"subtotal"`
Tax string `json:"tax,omitempty"`
Expand Down Expand Up @@ -216,7 +219,7 @@ type (

// Item maps to item object
Item struct {
Quantity string `json:"quantity"`
Quantity int `json:"quantity"`
Name string `json:"name"`
Price string `json:"price"`
Currency string `json:"currency"`
Expand Down Expand Up @@ -268,15 +271,15 @@ type (

// Payment maps to payment object
Payment struct {
Intent PaymentIntent `json:"intent"`
Payer *Payer `json:"payer"`
Transactions []Transaction `json:"transactions"`
RedirectURLs []RedirectURLs `json:"redirect_urls,omitempty"`
ID string `json:"id,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
State PaymentState `json:"state,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
ExperienceProfileID string `json:"experience_profile_id,omitempty"`
Intent PaymentIntent `json:"intent"`
Payer *Payer `json:"payer"`
Transactions []Transaction `json:"transactions"`
RedirectURLs *RedirectURLs `json:"redirect_urls,omitempty"`
ID string `json:"id,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
State PaymentState `json:"state,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
ExperienceProfileID string `json:"experience_profile_id,omitempty"`
}

// PaymentExecution maps to payment_execution object
Expand Down
13 changes: 7 additions & 6 deletions paypal.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ type (
// HTTP response that caused this error
Response *http.Response `json:"-"`

Name string `json:"name"`
DebugID string `json:"debug_id"`
Message string `json:"message"`
InformationLink string `json:"information_link"`
Details ErrorDetails `json:"details"`
Name string `json:"name"`
DebugID string `json:"debug_id"`
Message string `json:"message"`
InformationLink string `json:"information_link"`
Details []ErrorDetail `json:"details"`
}

// ErrorDetails map to error_details object
ErrorDetails struct {
ErrorDetail struct {
Field string `json:"field"`
Issue string `json:"issue"`
}
Expand Down Expand Up @@ -134,6 +134,7 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
if c := resp.StatusCode; c < 200 || c > 299 {
errResp := &ErrorResponse{Response: resp}
data, err := ioutil.ReadAll(resp.Body)

if err == nil && len(data) > 0 {
json.Unmarshal(data, errResp)
}
Expand Down
2 changes: 1 addition & 1 deletion refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "fmt"

// GetRefund returns a refund by ID
func (c *Client) GetRefund(refundID string) (*Refund, error) {
req, err := NewRequest("GET", fmt.Sprintf("%s/refund/%s", c.APIBase, refundID), nil)
req, err := NewRequest("GET", fmt.Sprintf("%s/payments/refund/%s", c.APIBase, refundID), nil)
if err != nil {
return nil, err
}
Expand Down
44 changes: 44 additions & 0 deletions vault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package paypal

import (
"fmt"
"time"
)

// https://developer.paypal.com/docs/api/#vault

type (
// VaultRequest maps to vault_request object
VaultRequest struct {
CreditCard
MerchantID string `json:"merchant_id,omitempty"`
ExternalCardID string `json:"external_card_id,omitempty"`
}

// VaultResponse maps to vault_response object
VaultResponse struct {
VaultRequest
CreateTime *time.Time `json: "create_time"`
UpdateTime *time.Time `json: "update_time"`
State string `json: "state"`
ValidUntil string `json: "valid_until"`
Links []Links `json:"links"`
}
)

// StoreInVault will store credit card details with PayPal.
func (c *Client) StoreInVault(cc VaultRequest) (*VaultResponse, error) {

req, err := NewRequest("POST", fmt.Sprintf("%s/vault/credit-cards", c.APIBase), cc)

if err != nil {
return nil, err
}
v := &VaultResponse{}

err = c.SendWithAuth(req, v)
if err != nil {
return nil, err
}
return v, nil
}