Skip to content

Commit

Permalink
Add PayPalDetails to Transactions
Browse files Browse the repository at this point in the history
What
===
Add `PayPalDetails` to `Transaction`.

Why
===
When `Transaction`s are created with a PayPal nonce or `PayPalAccount`
the details are not visible on the resulting `Transaction`.
  • Loading branch information
leighmcculloch committed Mar 4, 2017
1 parent d2743bd commit c0e3fe8
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
22 changes: 22 additions & 0 deletions paypal_details.go
@@ -0,0 +1,22 @@
package braintree

type PayPalDetails struct {
PayerEmail string `xml:"payer-email,omitempty"`
PaymentID string `xml:"payment-id,omitempty"`
AuthorizationID string `xml:"authorization-id,omitempty"`
Token string `xml:"token,omitempty"`
ImageURL string `xml:"image-url,omitempty"`
DebugID string `xml:"debug-id,omitempty"`
PayeeEmail string `xml:"payee-email,omitempty"`
CustomField string `xml:"custom-field,omitempty"`
PayerID string `xml:"payer-id,omitempty"`
PayerFirstName string `xml:"payer-first-name,omitempty"`
PayerLastName string `xml:"payer-last-name,omitempty"`
PayerStatus string `xml:"payer-status,omitempty"`
SellerProtectionStatus string `xml:"seller-protection-status,omitempty"`
RefundID string `xml:"refund-id,omitempty"`
CaptureID string `xml:"capture-id,omitempty"`
TransactionFeeAmount string `xml:"transaction-fee-amount,omitempty"`
TransactionFeeCurrencyISOCode string `xml:"transaction-fee-currency-iso-code,omitempty"`
Description string `xml:"description,omitempty"`
}
4 changes: 3 additions & 1 deletion transaction.go
@@ -1,8 +1,9 @@
package braintree

import (
"github.com/lionelbarrow/braintree-go/nullable"
"time"

"github.com/lionelbarrow/braintree-go/nullable"
)

type Transaction struct {
Expand Down Expand Up @@ -34,6 +35,7 @@ type Transaction struct {
ProcessorResponseText string `xml:"processor-response-text,omitempty"`
ProcessorAuthorizationCode string `xml:"processor-authorization-code,omitempty"`
SettlementBatchId string `xml:"settlement-batch-id,omitempty"`
PayPalDetails *PayPalDetails `xml:"paypal,omitempty"`
}

// TODO: not all transaction fields are implemented yet, here are the missing fields (add on demand)
Expand Down
81 changes: 81 additions & 0 deletions transaction_paypal_details_integration_test.go
@@ -0,0 +1,81 @@
package braintree

import "testing"

func TestTransactionPayPalDetails(t *testing.T) {
tx, err := testGateway.Transaction().Create(&Transaction{
Type: "sale",
Amount: NewDecimal(2000, 2),
PaymentMethodNonce: FakeNoncePayPalOneTimePayment,
})

t.Log(tx)

if err != nil {
t.Fatal(err)
}
if tx.Id == "" {
t.Fatal("Received invalid ID on new transaction")
}
if tx.Status != "authorized" {
t.Fatal(tx.Status)
}

if tx.PayPalDetails == nil {
t.Fatal("Expected PayPalDetails for transaction created with PayPal nonce")
}

t.Log(tx.PayPalDetails)

if tx.PayPalDetails.PayerEmail == "" {
t.Fatal("Expected PayPalDetails to have PayerEmail set")
}
if tx.PayPalDetails.PaymentID == "" {
t.Fatal("Expected PayPalDetails to have PaymentID set")
}
if tx.PayPalDetails.ImageURL == "" {
t.Fatal("Expected PayPalDetails to have ImageURL set")
}
if tx.PayPalDetails.DebugID == "" {
t.Fatal("Expected PayPalDetails to have DebugID set")
}
if tx.PayPalDetails.PayerID == "" {
t.Fatal("Expected PayPalDetails to have DebugID set")
}
if tx.PayPalDetails.PayerFirstName == "" {
t.Fatal("Expected PayPalDetails to have PayerFirstName set")
}
if tx.PayPalDetails.PayerLastName == "" {
t.Fatal("Expected PayPalDetails to have PayerLastName set")
}
if tx.PayPalDetails.PayerStatus == "" {
t.Fatal("Expected PayPalDetails to have PayerStatus set")
}
if tx.PayPalDetails.SellerProtectionStatus == "" {
t.Fatal("Expected PayPalDetails to have SellerProtectionStatus set")
}
}

func TestTransactionWithoutPayPalDetails(t *testing.T) {
tx, err := testGateway.Transaction().Create(&Transaction{
Type: "sale",
Amount: NewDecimal(2000, 2),
PaymentMethodNonce: FakeNonceTransactable,
})

t.Log(tx)

if err != nil {
t.Fatal(err)
}
if tx.Id == "" {
t.Fatal("Received invalid ID on new transaction")
}
if tx.Status != "authorized" {
t.Fatal(tx.Status)
}

if tx.PayPalDetails != nil {
t.Fatalf("Expected PayPalDetails to be nil for transaction created without PayPal, but was %#v", tx.PayPalDetails)
}
}

0 comments on commit c0e3fe8

Please sign in to comment.