Skip to content
This repository has been archived by the owner on Feb 6, 2019. It is now read-only.
/ go-paypalnvp Public archive

(Archived) Interact with the PayPal NVP endpoint.

Notifications You must be signed in to change notification settings

vidsy/go-paypalnvp

Repository files navigation

This repo is archived, and is now used for reference.


go-paypal-nvp

Library for interacting with the PayPal NVP endpoint.

Usage

Currently the library supports the following methods:

  • MassPayment

With others coming soon.

Authentication

Only API credentials are supported at present, however the client takes a compatible http client that implements the TransportClient interface so a net/http client can be created with client cert authentication setup and passed in.

Example

Below is an example setting up and preforming a Mass Payment:

package main

import (
	"fmt"

	"github.com/vidsy/go-paypalnvp"
	"github.com/vidsy/go-paypalnvp/payload"
)

func main() {

	client := paypalnvp.NewClient(
		nil,
		paypalnvp.Sandbox,
		"user",
		"password",
		"signature",
	)

	massPayment := payload.NewMassPayment("GBP", payload.ReceiverTypeEmail)
	massPaymentItem := payload.MassPaymentItem{
		Email:  "[email protected]",
		Amount: 100.50,
		ID:     "123456789",
		Note:   "Vidsy payment going out",
	}
	massPayment.AddItem(massPaymentItem)

	response, err := client.Execute(massPayment)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Successful: %t\n", response.Successful())
	fmt.Printf("Errors count: %d\n", response.ErrorCount())

	if response.ErrorCount() > 0 {
		fmt.Printf("Error code: %s\n", response.Errors[0].Code)
		fmt.Printf("Long message: %s\n", response.Errors[0].LongMessage)
	}
}