Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,48 @@ jobs:
- name: Build Release
run: dotnet build src -c Release /p:ContinuousIntegrationBuild=true

- name: Determine OpenAPI versions and extract specs
run: |
set -e -o pipefail

CURL_OPTS=(--retry 3 \
--retry-all-errors \
--fail \
--verbose \
--no-progress-meter \
--show-error)

LATEST_OPENAPI_VERSION=$(curl https://api.github.com/repos/stripe/openapi/releases/latest -s | jq .name -r)
CURRENT_OPENAPI_VERSION=$(cat OPENAPI_VERSION)
if [[ "$PR_BODY" == *"TEST USING LATEST OPENAPI"* ]]; then
OPENAPI_VERSION=$LATEST_OPENAPI_VERSION
else
OPENAPI_VERSION=$CURRENT_OPENAPI_VERSION
fi

CURRENT_OPENAPI_SPEC=$(realpath latest.yaml)
CURRENT_OPENAPI_SPEC_JSON=${CURRENT_OPENAPI_SPEC%.yaml}.json
CURRENT_FIXTURES_JSON=${CURRENT_OPENAPI_SPEC%/*}/fixtures.json

SPEC_NAME="spec3.sdk.yaml"
FIXTURES_NAME="fixtures3.json"
if [[ "$GITHUB_BASE" == *"b"* ]]; then
SPEC_NAME="spec3.beta.sdk.yaml"
FIXTURES_NAME="fixtures3.beta.json"
fi
curl "${CURL_OPTS[@]}" https://raw.githubusercontent.com/stripe/openapi/$OPENAPI_VERSION/openapi/${SPEC_NAME%.yaml}.json -o $CURRENT_OPENAPI_SPEC_JSON
curl "${CURL_OPTS[@]}" https://raw.githubusercontent.com/stripe/openapi/$OPENAPI_VERSION/openapi/$FIXTURES_NAME -o $CURRENT_FIXTURES_JSON

env:
PR_BODY: ${{ github.event.pull_request.body }}
GITHUB_BASE: ${{ github.base_ref || github.ref_name }}

- uses: stripe/openapi/actions/stripe-mock@master
with:
# Used to determine if stripe-mock runs in beta mode
base: ${{ github.base_ref || github.ref_name }}
fixtures: "/workspace/fixtures.json"
spec_path: "/workspace/latest.json"

- name: Run test suite
run: just ci-test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public class AccountExternalAccountBankAccountOptions : INestedOptions, IHasObje
public string Currency { get; set; }

/// <summary>
/// The routing number, sort code, or other country-appropriateinstitution number for the
/// bank account. For US bank accounts, this is required and should bethe ACH routing
/// number, not the wire routing number. If you are providing an IBAN
/// for<c>account_number</c>, this field is not required.
/// The routing number, sort code, or other country-appropriate institution number for the
/// bank account. For US bank accounts, this is required and should be the ACH routing
/// number, not the wire routing number. If you are providing an IBAN for
/// <c>account_number</c>, this field is not required.
/// </summary>
[JsonProperty("routing_number")]
#if NET6_0_OR_GREATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public class AccountBankAccountOptions : INestedOptions, IHasObject
public string Object { get; set; } = "bank_account";

/// <summary>
/// The routing number, sort code, or other country-appropriateinstitution number for the
/// bank account. For US bank accounts, this is required and should bethe ACH routing
/// number, not the wire routing number. If you are providing an IBAN
/// for<c>account_number</c>, this field is not required.
/// The routing number, sort code, or other country-appropriate institution number for the
/// bank account. For US bank accounts, this is required and should be the ACH routing
/// number, not the wire routing number. If you are providing an IBAN for
/// <c>account_number</c>, this field is not required.
/// </summary>
[JsonProperty("routing_number")]
#if NET6_0_OR_GREATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public BalanceTransactionTest(StripeMockFixture stripeMockFixture)
[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/balance_transactions/txn_123");
var json = GetResourceAsString("api_fixtures.balance_transaction.json");
var balanceTransaction = JsonConvert.DeserializeObject<BalanceTransaction>(json);
Assert.NotNull(balanceTransaction);
Assert.IsType<BalanceTransaction>(balanceTransaction);
Expand Down
50 changes: 50 additions & 0 deletions src/StripeTests/Entities/BankAccounts/BankAccountTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace StripeTests
{
using Newtonsoft.Json;
using Stripe;
using Xunit;

public class BankAccountTest : BaseStripeTest
{
public BankAccountTest(StripeMockFixture stripeMockFixture)
: base(stripeMockFixture)
{
}

[Fact]
public void DeserializeForAccount()
{
string json = this.GetFixture("/v1/accounts/acct_123/external_accounts/ba_123");
var bankAccount = JsonConvert.DeserializeObject<BankAccount>(json);
Assert.NotNull(bankAccount);
Assert.IsType<BankAccount>(bankAccount);
Assert.NotNull(bankAccount.Id);
Assert.Equal("bank_account", bankAccount.Object);
}

[Fact]
public void DeserializeForCustomer()
{
var json = GetResourceAsString("api_fixtures.bank_account.json");
var bankAccount = JsonConvert.DeserializeObject<BankAccount>(json);
Assert.NotNull(bankAccount);
Assert.IsType<BankAccount>(bankAccount);
Assert.NotNull(bankAccount.Id);
Assert.Equal("bank_account", bankAccount.Object);
}

[Fact]
public void DeserializeWithExpansionsForCustomer()
{
var json = GetResourceAsString("api_fixtures.bank_account_with_expansion.json");
var bankAccount = JsonConvert.DeserializeObject<BankAccount>(json);
Assert.NotNull(bankAccount);
Assert.IsType<BankAccount>(bankAccount);
Assert.NotNull(bankAccount.Id);
Assert.Equal("bank_account", bankAccount.Object);

Assert.NotNull(bankAccount.Customer);
Assert.Equal("customer", bankAccount.Customer.Object);
}
}
}
39 changes: 39 additions & 0 deletions src/StripeTests/Entities/Cards/CardTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace StripeTests
{
using Newtonsoft.Json;
using Stripe;
using Xunit;

public class CardTest : BaseStripeTest
{
public CardTest(StripeMockFixture stripeMockFixture)
: base(stripeMockFixture)
{
}

[Fact]
public void Deserialize()
{
var json = GetResourceAsString("api_fixtures.customer_card.json");
var card = JsonConvert.DeserializeObject<Card>(json);
Assert.NotNull(card);
Assert.IsType<Card>(card);
Assert.NotNull(card.Id);
Assert.Equal("card", card.Object);
}

[Fact]
public void DeserializeWithExpansions()
{
var json = GetResourceAsString("api_fixtures.customer_card_with_expansion.json");
var card = JsonConvert.DeserializeObject<Card>(json);
Assert.NotNull(card);
Assert.IsType<Card>(card);
Assert.NotNull(card.Id);
Assert.Equal("card", card.Object);

Assert.NotNull(card.Customer);
Assert.Equal("customer", card.Customer.Object);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public SubscriptionScheduleTest(StripeMockFixture stripeMockFixture)
[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/subscription_schedules/sub_sched_123");
var json = GetResourceAsString("api_fixtures.subscription_schedule.json");
var schedule = JsonConvert.DeserializeObject<SubscriptionSchedule>(json);
Assert.NotNull(schedule);
Assert.IsType<SubscriptionSchedule>(schedule);
Expand All @@ -25,16 +25,7 @@ public void Deserialize()
[Fact]
public void DeserializeWithExpansions()
{
// TODO: support expanding "phases.coupon" and "phases.plans.plan" and others with stripe-mock
string[] expansions =
{
"customer",
"default_settings.default_payment_method",
"phases.plans.plan",
"subscription",
};

string json = this.GetFixture("/v1/subscription_schedules/sub_sched_123", expansions);
var json = GetResourceAsString("api_fixtures.subscription_schedule_with_expansions.json");
var schedule = JsonConvert.DeserializeObject<SubscriptionSchedule>(json);
Assert.NotNull(schedule);
Assert.IsType<SubscriptionSchedule>(schedule);
Expand Down
12 changes: 2 additions & 10 deletions src/StripeTests/Entities/Subscriptions/SubscriptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public SubscriptionTest(StripeMockFixture stripeMockFixture)
[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/subscriptions/sub_123");
var json = GetResourceAsString("api_fixtures.subscription.json");
var subscription = JsonConvert.DeserializeObject<Subscription>(json);
Assert.NotNull(subscription);
Assert.IsType<Subscription>(subscription);
Expand All @@ -25,15 +25,7 @@ public void Deserialize()
[Fact]
public void DeserializeWithExpansions()
{
string[] expansions =
{
"customer",
"default_payment_method",
"latest_invoice",
"pending_setup_intent",
};

string json = this.GetFixture("/v1/subscriptions/sub_123", expansions);
var json = GetResourceAsString("api_fixtures.subscription_with_expansions.json");
var subscription = JsonConvert.DeserializeObject<Subscription>(json);
Assert.NotNull(subscription);
Assert.IsType<Subscription>(subscription);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "txn_123",
"object": "balance_transaction",
"source": {
"id": "random",
"object": "unknown_object"
}
}
16 changes: 16 additions & 0 deletions src/StripeTests/Resources/api_fixtures/bank_account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"account_holder_name": "Jane Austen",
"account_holder_type": "company",
"account_type": null,
"bank_name": "STRIPE TEST BANK",
"country": "US",
"currency": "usd",
"customer": null,
"fingerprint": "AuoSJ18zsVWV9SPc",
"id": "ba_123",
"last4": "6789",
"metadata": {},
"object": "bank_account",
"routing_number": "110000000",
"status": "new"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"account_holder_name": "Jane Austen",
"account_holder_type": "company",
"account_type": null,
"bank_name": "STRIPE TEST BANK",
"country": "US",
"currency": "usd",
"customer": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"balance": 0,
"created": 1234567890,
"currency": "usd",
"default_source": null,
"delinquent": false,
"description": null,
"discount": {
"checkout_session": null,
"coupon": {
"amount_off": null,
"created": 1028554472,
"currency": null,
"duration": "forever",
"duration_in_months": null,
"id": "obj_123",
"livemode": true,
"max_redemptions": null,
"metadata": null,
"name": null,
"object": "coupon",
"percent_off": null,
"redeem_by": null,
"times_redeemed": 990066668,
"valid": true
},
"customer": null,
"end": null,
"id": "obj_123",
"invoice": null,
"invoice_item": null,
"object": "discount",
"promotion_code": null,
"start": 109757538,
"subscription": null,
"subscription_item": null
},
"email": null,
"id": "cus_123",
"invoice_prefix": "7FE1103",
"invoice_settings": {
"custom_fields": null,
"default_payment_method": null,
"footer": null,
"rendering_options": {
"amount_tax_display": null,
"template": null
}
},
"livemode": false,
"metadata": {},
"name": null,
"next_invoice_sequence": 1,
"object": "customer",
"phone": null,
"preferred_locales": [],
"shipping": {},
"tax_exempt": "none",
"test_clock": null
},
"fingerprint": "AuoSJ18zsVWV9SPc",
"id": "ba_123",
"last4": "6789",
"metadata": {},
"object": "bank_account",
"routing_number": "110000000",
"status": "new"
}
26 changes: 26 additions & 0 deletions src/StripeTests/Resources/api_fixtures/customer_card.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": null,
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 8,
"exp_year": 2025,
"fingerprint": "AOB934RVNwzk6xtn",
"funding": "credit",
"id": "card_123",
"last4": "4242",
"metadata": {},
"name": "Jenny Rosen",
"object": "card",
"regulated_status": null,
"tokenization_method": null
}
Loading
Loading