-
Notifications
You must be signed in to change notification settings - Fork 573
/
Copy pathPaymentIntentTest.cs
113 lines (95 loc) · 4.16 KB
/
PaymentIntentTest.cs
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
113
namespace StripeTests
{
using Stripe;
using Xunit;
public class PaymentIntentTest : BaseStripeTest
{
[Fact]
public void Deserialize()
{
string json = GetFixture("/v1/payment_intents/pi_123");
var intent = Mapper<PaymentIntent>.MapFromJson(json);
Assert.NotNull(intent);
Assert.IsType<PaymentIntent>(intent);
Assert.NotNull(intent.Id);
Assert.Equal("payment_intent", intent.Object);
}
[Fact]
public void DeserializeWithExpansions()
{
// Do not test expanding `source` as it is not supported by stripe-mock
// and will be auto-expanded in a future API version.
string[] expansions =
{
"application",
"customer",
"transfer_data.destination",
};
string json = GetFixture("/v1/payment_intents/pi_123", expansions);
var intent = Mapper<PaymentIntent>.MapFromJson(json);
Assert.NotNull(intent);
Assert.IsType<PaymentIntent>(intent);
Assert.NotNull(intent.Id);
Assert.Equal("payment_intent", intent.Object);
Assert.NotNull(intent.Application);
Assert.Equal("application", intent.Application.Object);
Assert.NotNull(intent.Customer);
Assert.Equal("customer", intent.Customer.Object);
Assert.NotNull(intent.TransferData);
Assert.NotNull(intent.TransferData.Destination);
Assert.Equal("account", intent.TransferData.Destination.Object);
}
[Fact]
public void DeserializeNextSourceActionNull()
{
var json = GetResourceAsString("api_fixtures.payment_intent.action_null.json");
var intent = Mapper<PaymentIntent>.MapFromJson(json);
Assert.NotNull(intent);
Assert.IsType<PaymentIntent>(intent);
Assert.NotNull(intent.Id);
Assert.Equal("payment_intent", intent.Object);
Assert.Null(intent.NextSourceAction);
}
[Fact]
public void DeserializeNextSourceActionAuthorizeWithUrl()
{
var json = GetResourceAsString("api_fixtures.payment_intent.action_authorize_with_url.json");
var intent = Mapper<PaymentIntent>.MapFromJson(json);
Assert.NotNull(intent);
Assert.IsType<PaymentIntent>(intent);
Assert.NotNull(intent.Id);
Assert.Equal("payment_intent", intent.Object);
Assert.Equal("authorize_with_url", intent.NextSourceAction.Type);
Assert.NotNull(intent.NextSourceAction.AuthorizeWithUrl);
Assert.Equal("https://stripe.com", intent.NextSourceAction.AuthorizeWithUrl.Url);
Assert.Equal("https://stripe.com/return", intent.NextSourceAction.AuthorizeWithUrl.ReturnUrl);
}
[Fact]
public void DeserializeNextSourceActionUnknown()
{
var json = GetResourceAsString("api_fixtures.payment_intent.action_unknown.json");
var intent = Mapper<PaymentIntent>.MapFromJson(json);
Assert.NotNull(intent);
Assert.IsType<PaymentIntent>(intent);
Assert.NotNull(intent.Id);
Assert.Equal("payment_intent", intent.Object);
Assert.Equal("foo", intent.NextSourceAction.Type);
Assert.Null(intent.NextSourceAction.AuthorizeWithUrl);
}
[Fact]
public void DeserializeLastPaymentError()
{
var json = GetResourceAsString("api_fixtures.payment_intent.last_payment_error.json");
var intent = Mapper<PaymentIntent>.MapFromJson(json);
Assert.NotNull(intent);
Assert.IsType<PaymentIntent>(intent);
Assert.NotNull(intent.Id);
Assert.Equal("payment_intent", intent.Object);
var lastPaymentError = intent.LastPaymentError;
Assert.NotNull(lastPaymentError);
Assert.Equal("generic_decline", lastPaymentError.DeclineCode);
Assert.IsType<Card>(lastPaymentError.Source);
Assert.Equal("card_123", lastPaymentError.Source.Id);
}
}
}