-
Notifications
You must be signed in to change notification settings - Fork 12
/
response_test.go
112 lines (102 loc) · 3.77 KB
/
response_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package amazonpay
import (
"encoding/xml"
"fmt"
"testing"
)
func TestOrderReferenceDetails(t *testing.T) {
resp := `<GetOrderReferenceDetailsResponse xmlns="http://mws.amazonservices.com/schema/OffAmazonPayments/2013-01-01">
<GetOrderReferenceDetailsResult>
<OrderReferenceDetails>
<OrderReferenceStatus>
<State>Draft</State>
</OrderReferenceStatus>
<Destination>
<DestinationType>Physical</DestinationType>
<PhysicalDestination>
<StateOrRegion>Tokyo</StateOrRegion>
<City>Ota-ku</City>
<CountryCode>JP</CountryCode>
<PostalCode>144-8588</PostalCode>
</PhysicalDestination>
</Destination>
<ExpirationTimestamp>2018-08-28T16:00:23.013Z</ExpirationTimestamp>
<IdList/>
<SellerOrderAttributes/>
<OrderTotal>
<CurrencyCode>JPY</CurrencyCode>
<Amount>23.00</Amount>
</OrderTotal>
<ReleaseEnvironment>Sandbox</ReleaseEnvironment>
<AmazonOrderReferenceId>S03-1594298-4362493</AmazonOrderReferenceId>
<CreationTimestamp>2018-03-01T16:00:23.013Z</CreationTimestamp>
<RequestPaymentAuthorization>false</RequestPaymentAuthorization>
</OrderReferenceDetails>
</GetOrderReferenceDetailsResult>
<ResponseMetadata>
<RequestId>ae47aef3-e030-4fdf-a0bb-87c4767e63d6</RequestId>
</ResponseMetadata>
</GetOrderReferenceDetailsResponse>`
detail := GetOrderReferenceDetailsResponse{}
if err := xml.Unmarshal([]byte(resp), &detail); err != nil {
t.Errorf("no error should get when unmarshal order reference detail, but got %v", err)
}
fmt.Printf("%#v", detail)
}
func TestAuthorizeResponse(t *testing.T) {
resp := `<AuthorizeResponse xmlns="http://mws.amazonservices.com/schema/OffAmazonPayments/2013-01-01">
<AuthorizeResult>
<AuthorizationDetails>
<AuthorizationAmount>
<CurrencyCode>JPY</CurrencyCode>
<Amount>134.00</Amount>
</AuthorizationAmount>
<CapturedAmount>
<CurrencyCode>JPY</CurrencyCode>
<Amount>0</Amount>
</CapturedAmount>
<ExpirationTimestamp>2018-04-01T06:21:12.317Z</ExpirationTimestamp>
<IdList/>
<SoftDecline>false</SoftDecline>
<AuthorizationStatus>
<LastUpdateTimestamp>2018-03-02T06:21:12.317Z</LastUpdateTimestamp>
<State>Pending</State>
</AuthorizationStatus>
<AuthorizationFee>
<CurrencyCode>JPY</CurrencyCode>
<Amount>0.00</Amount>
</AuthorizationFee>
<CaptureNow>false</CaptureNow>
<SellerAuthorizationNote/>
<CreationTimestamp>2018-03-02T06:21:12.317Z</CreationTimestamp>
<AmazonAuthorizationId>S03-0775027-3039214-A074087</AmazonAuthorizationId>
<AuthorizationReferenceId>225</AuthorizationReferenceId>
</AuthorizationDetails>
</AuthorizeResult>
<ResponseMetadata>
<RequestId>a4e98146-b2f9-43b8-8ebf-364e1454b222</RequestId>
</ResponseMetadata>
</AuthorizeResponse>`
detail := AuthorizeResponse{}
if err := xml.Unmarshal([]byte(resp), &detail); err != nil {
t.Errorf("no error should get when unmarshal order reference detail, but got %v", err)
}
fmt.Printf("%#v", detail)
}
func TestErrorResponse(t *testing.T) {
resp := `<ErrorResponse xmlns="http://mws.amazonservices.com/schema/OffAmazonPayments/2013-01-01">
<Error>
<Type>Sender</Type>
<Code>DuplicateReferenceId</Code>
<Message>Your Capture request could not be processed because an Authorize request with the ReferenceId 226 already exists.</Message>
</Error>
<RequestId>9547ad10-46da-4759-b37c-82ad02b0c1af</RequestId>
</ErrorResponse>`
detail := APIError{}
if err := xml.Unmarshal([]byte(resp), &detail); err != nil {
t.Errorf("no error should get when unmarshal order reference detail, but got %v", err)
}
if detail.Code != "DuplicateReferenceId" {
t.Errorf("Error not decoded")
}
}