-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature for GetTransactionDetails
- Loading branch information
1 parent
19b236b
commit 5cdf828
Showing
6 changed files
with
200 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package merchant | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// BaseRequest is base struct for api request | ||
type BaseRequest struct { | ||
Method string `url:"METHOD"` | ||
Action string `url:"PAYMENTREQUEST_0_PAYMENTACTION,omitempty"` | ||
} | ||
|
||
// BaseResponse is base struct for api response | ||
type BaseResponse struct { | ||
Timestamp string `url:"TIMESTAMP"` | ||
ACK string `url:"ACK"` | ||
Version string `url:"VERSION"` | ||
Build string `url:"BUILD"` | ||
CorrelationID string `url:"CORRELATIONID"` | ||
|
||
// error0 | ||
ErrorCode string `url:"L_ERRORCODE0"` | ||
ShortMessage string `url:"L_SHORTMESSAGE0"` | ||
LongMessage string `url:"L_LONGMESSAGE0"` | ||
SeverityCode string `url:"L_SEVERITYCODE0"` | ||
|
||
// error1 | ||
ErrorCode1 string `url:"L_ERRORCODE1"` | ||
ShortMessage1 string `url:"L_SHORTMESSAGE1"` | ||
LongMessage1 string `url:"L_LONGMESSAGE1"` | ||
SeverityCode1 string `url:"L_SEVERITYCODE1"` | ||
} | ||
|
||
func (r BaseResponse) baseError() []string { | ||
var errs []string | ||
if r.ShortMessage != "" { | ||
errs = append(errs, r.ShortMessage+" "+r.LongMessage) | ||
} | ||
if r.ShortMessage1 != "" { | ||
errs = append(errs, r.ShortMessage1+" "+r.LongMessage1) | ||
} | ||
return errs | ||
} | ||
|
||
// Error returns error message | ||
func (r BaseResponse) Error() string { | ||
return parseErrors(r.baseError()) | ||
} | ||
|
||
// Errors returns error messages | ||
func (r BaseResponse) Errors(s []string) string { | ||
errs := r.baseError() | ||
errs = append(errs, s...) | ||
return parseErrors(errs) | ||
} | ||
|
||
func parseErrors(errs []string) string { | ||
return strings.Join(errs, ",") | ||
} | ||
|
||
// MerchantResponse is interface of response from each API | ||
type MerchantResponse interface { | ||
IsSuccess() bool | ||
IsRequestSuccess() bool | ||
IsOperationSuccess() bool | ||
Error() string | ||
} | ||
|
||
// ShippingResponse is for shipping information | ||
type ShippingResponse struct { | ||
ShipToName string `url:"SHIPTONAME"` | ||
ShipToStreet string `url:"SHIPTOSTREET"` | ||
ShipToCity string `url:"SHIPTOCITY"` | ||
ShipToState string `url:"SHIPTOSTATE"` | ||
ShipToZip string `url:"SHIPTOZIP"` | ||
ShipToCountryCode string `url:"SHIPTOCOUNTRYCODE"` | ||
ShipToCountry string `url:"SHIPTOCOUNTRY"` | ||
ShipToCountryName string `url:"SHIPTOCOUNTRYNAME"` | ||
ShipAddressOwner string `url:"SHIPADDRESSOWNER"` | ||
ShipAddressStatus string `url:"SHIPADDRESSSTATUS"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package merchant | ||
|
||
// GetTransactionDetails is struct for GetTransactionDetails API | ||
// see: https://developer.paypal.com/docs/classic/api/merchant/GetTransactionDetails_API_Operation_NVP/ | ||
type GetTransactionDetails struct { | ||
Merchant `url:",squash"` | ||
BaseRequest `url:",squash"` | ||
|
||
TransactionID string `url:"TRANSACTIONID"` | ||
} | ||
|
||
// SetMerchant sets Merchant | ||
func (svc *GetTransactionDetails) SetMerchant(m Merchant) { | ||
svc.Merchant = m | ||
} | ||
|
||
// Do executes GetTransactionDetails operation | ||
func (svc *GetTransactionDetails) Do(m Merchant) (*GetTransactionDetailsResponse, error) { | ||
const method = "GetTransactionDetails" | ||
svc.BaseRequest.Method = method | ||
|
||
result := &GetTransactionDetailsResponse{} | ||
err := m.call(svc, result) | ||
return result, err | ||
} | ||
|
||
// GetTransactionDetailsResponse is struct for response of GetTransactionDetails API | ||
type GetTransactionDetailsResponse struct { | ||
BaseResponse `url:",squash"` | ||
|
||
// success | ||
TransactionID string `url:"TRANSACTIONID"` | ||
TransactionType string `url:"TRANSACTIONTYPE"` | ||
PaymentType string `url:"PAYMENTTYPE"` | ||
Subject string `url:"SUBJECT"` | ||
|
||
CurrencyCode string `url:"CURRENCYCODE"` | ||
Amount string `url:"AMT"` | ||
ShippingAmount string `url:"SHIPPINGAMT"` | ||
TaxAmount string `url:"TAXAMT"` | ||
FeeAmount string `url:"FEEAMT"` | ||
OrderTime string `url:"ORDERTIME"` | ||
|
||
PaymentStatus string `url:"PAYMENTSTATUS"` | ||
PendingReason string `url:"PENDINGREASON"` | ||
ReasonCode string `url:"REASONCODE"` | ||
ProtectionEligibility string `url:"PROTECTIONELIGIBILITY"` | ||
ProtectionEligibilityType string `url:"PROTECTIONELIGIBILITYTYPE"` | ||
|
||
PayerID string `url:"PAYERID"` | ||
PayerStatus string `url:"PAYERSTATUS"` | ||
FirstName string `url:"FIRSTNAME"` | ||
LastName string `url:"LASTNAME"` | ||
Emain string `url:"EMAIL"` | ||
ReceiverID string `url:"RECEIVERID"` | ||
ReceiverEmail string `url:"RECEIVEREMAIL"` | ||
CountryCode string `url:"COUNTRYCODE"` | ||
AddressOwner string `url:"ADDRESSOWNER"` | ||
AddressStatus string `url:"ADDRESSSTATUS"` | ||
|
||
SalesTax string `url:"SALESTAX"` | ||
ShipAmount string `url:"SHIPAMOUNT"` | ||
ShipHandleAmount string `url:"SHIPHANDLEAMOUNT"` | ||
|
||
ShippingResponse `url:",squash"` | ||
} | ||
|
||
// IsSuccess checks the request is success or not | ||
func (r *GetTransactionDetailsResponse) IsSuccess() bool { | ||
return r.IsRequestSuccess() && r.IsOperationSuccess() | ||
} | ||
|
||
// IsRequestSuccess checks the request is success or not | ||
func (r *GetTransactionDetailsResponse) IsRequestSuccess() bool { | ||
return r.ACK == ackSuccess | ||
} | ||
|
||
// IsOperationSuccess checks the request is success or not | ||
func (r *GetTransactionDetailsResponse) IsOperationSuccess() bool { | ||
return r.PaymentStatus == paymentStatusComleted | ||
} | ||
|
||
// Error returns error text | ||
func (r *GetTransactionDetailsResponse) Error() string { | ||
return r.BaseResponse.Error() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package merchant | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetTransactionDetails(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
m := NewDefault() | ||
// error | ||
svc := &GetTransactionDetails{ | ||
TransactionID: "XXXXXXXXXXXXX", | ||
} | ||
v, err := svc.Do(m) | ||
|
||
assert.Nil(err) | ||
assert.Equal("Failure", v.ACK) | ||
assert.Equal("124", v.Version) | ||
assert.Equal("000000", v.Build) | ||
assert.Equal("10004", v.ErrorCode) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters