Skip to content

Commit

Permalink
Create non profit endpoint support added
Browse files Browse the repository at this point in the history
  • Loading branch information
diegostamigni committed Apr 21, 2023
1 parent a5e741b commit 153d286
Show file tree
Hide file tree
Showing 26 changed files with 730 additions and 583 deletions.
59 changes: 29 additions & 30 deletions Rest.GetChangeio.Abstractions/IDonationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@
using Rest.GetChangeio.Responses;
using Rest.GetChangeio.ServiceModel;

namespace Rest.GetChangeio.Abstractions
namespace Rest.GetChangeio.Abstractions;

/// <summary>
/// To create a donation, use the /donations/create endpoint.
/// In the response, you'll get a donation ID, which you can use to retrieve information about your donation.
/// We also have endpoints that simplify making carbon offset donations.
/// </summary>
public interface IDonationService
{
/// <summary>
/// To create a donation, use the /donations/create endpoint.
/// In the response, you'll get a donation ID, which you can use to retrieve information about your donation.
/// We also have endpoints that simplify making carbon offset donations.
/// Creates a donation to any nonprofit. CHANGE keeps track of your donations, bills you at the end of the month,
/// and handles the nonprofit payouts for you.
/// </summary>
public interface IDonationService
{
/// <summary>
/// Creates a donation to any nonprofit. CHANGE keeps track of your donations, bills you at the end of the month,
/// and handles the nonprofit payouts for you.
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns>The resulting donation.</returns>
Task<Donation?> CreateAsync(CreateDonationRequest request, CancellationToken token = default);
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns>The resulting donation.</returns>
Task<Donation?> CreateAsync(CreateDonationRequest request, CancellationToken token = default);

/// <summary>
/// Retrieves the details of a donation you've previously made.
/// </summary>
/// <param name="id">The id of a donation. Ids are returned when a donation is created.</param>
/// <param name="token"></param>
/// <returns>The requested donation.</returns>
Task<Donation?> GetAsync(string id, CancellationToken token = default);
/// <summary>
/// Retrieves the details of a donation you've previously made.
/// </summary>
/// <param name="id">The id of a donation. Ids are returned when a donation is created.</param>
/// <param name="token"></param>
/// <returns>The requested donation.</returns>
Task<Donation?> GetAsync(string id, CancellationToken token = default);

/// <summary>
/// Retrieves a list of donations you've previously made. The donations are returned in order of creation,
/// with the most recent donations appearing first. This endpoint is paginated.
/// </summary>
/// <param name="page">Which page to return. This endpoint is paginated, and returns maximum 30 donations per page.</param>
/// <param name="token"></param>
/// <returns>Retrieves a list of donations you've previously made.</returns>
Task<GetDonationsResponse?> GetAllAsync(int page = 1, CancellationToken token = default);
}
/// <summary>
/// Retrieves a list of donations you've previously made. The donations are returned in order of creation,
/// with the most recent donations appearing first. This endpoint is paginated.
/// </summary>
/// <param name="page">Which page to return. This endpoint is paginated, and returns maximum 30 donations per page.</param>
/// <param name="token"></param>
/// <returns>Retrieves a list of donations you've previously made.</returns>
Task<GetDonationsResponse?> GetAllAsync(int page = 1, CancellationToken token = default);
}
11 changes: 5 additions & 6 deletions Rest.GetChangeio.Abstractions/IGetChangeioConfig.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace Rest.GetChangeio.Abstractions
namespace Rest.GetChangeio.Abstractions;

public interface IGetChangeioConfig
{
public interface IGetChangeioConfig
{
public string? GetChangeioPublicKey { get; set; }
public string? GetChangeioPublicKey { get; set; }

public string? GetChangeioSecretKey { get; set; }
}
public string? GetChangeioSecretKey { get; set; }
}
118 changes: 63 additions & 55 deletions Rest.GetChangeio.Abstractions/INonprofitsService.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,76 @@
using System.Threading;
using System.Threading.Tasks;
using Rest.GetChangeio.Requests;
using Rest.GetChangeio.Responses;
using Rest.GetChangeio.ServiceModel;

namespace Rest.GetChangeio.Abstractions
namespace Rest.GetChangeio.Abstractions;

/// <summary>
/// Most U.S. nonprofits exist in the CHANGE platform. Each nonprofit has a CHANGE-issued ID;
/// these IDs are used to reference nonprofits throughout our APIs. You can search for nonprofits manually on
/// the dashboard, or you can search programmatically.
/// </summary>
public interface INonprofitsService
{
/// <summary>
/// Most U.S. nonprofits exist in the CHANGE platform. Each nonprofit has a CHANGE-issued ID;
/// these IDs are used to reference nonprofits throughout our APIs. You can search for nonprofits manually on
/// the dashboard, or you can search programmatically.
/// Retrieves information for a nonprofit.
/// </summary>
/// <param name="id">The id of a nonprofit from the CHANGE network.</param>
/// <param name="token"></param>
/// <returns></returns>
Task<Nonprofit?> GetAsync(string id, CancellationToken token = default);

/// <summary>
/// Retrieves a list of nonprofits whose names match the provided name. This endpoint is paginated.
/// </summary>
public interface INonprofitsService
{
/// <summary>
/// Retrieves information for a nonprofit.
/// </summary>
/// <param name="id">The id of a nonprofit from the CHANGE network.</param>
/// <param name="token"></param>
/// <returns></returns>
Task<Nonprofit?> GetAsync(string id, CancellationToken token = default);
/// <param name="name">A string to search.</param>
/// <param name="page">The page to return. This endpoint is paginated, and returns up to 30 nonprofits at a time.</param>
/// <param name="token"></param>
/// <returns>A paginated list of nonprofits.</returns>
Task<SearchNonprofitsResponse?> SearchAsync(string name, int page = 1, CancellationToken token = default);

/// <summary>
/// Retrieves a list of nonprofits whose names match the provided name. This endpoint is paginated.
/// </summary>
/// <param name="name">A string to search.</param>
/// <param name="page">The page to return. This endpoint is paginated, and returns up to 30 nonprofits at a time.</param>
/// <param name="token"></param>
/// <returns>A paginated list of nonprofits.</returns>
Task<SearchNonprofitsResponse?> SearchAsync(string name, int page = 1, CancellationToken token = default);
/// <summary>
/// Retrieves a list of nonprofits whose names match the provided name. This endpoint is paginated.
/// </summary>
/// <param name="name">A string to search.</param>
/// <param name="categories">List of categories to search. Valid categories are: 'arts and culture',
/// 'education', 'environment', 'animals', 'healthcare', 'human services', 'international affairs',
/// 'public benefit', 'religion', 'mutual benefit', 'unclassified'.</param>
/// <param name="page">The page to return. This endpoint is paginated, and returns up to 30 nonprofits at a time.</param>
/// <param name="token"></param>
/// <returns>A paginated list of nonprofits.</returns>
Task<SearchNonprofitsResponse?> SearchAsync(
string name,
string[] categories,
int page = 1,
CancellationToken token = default);

/// <summary>
/// Retrieves a list of nonprofits whose names match the provided name. This endpoint is paginated.
/// </summary>
/// <param name="name">A string to search.</param>
/// <param name="categories">List of categories to search. Valid categories are: 'arts and culture',
/// 'education', 'environment', 'animals', 'healthcare', 'human services', 'international affairs',
/// 'public benefit', 'religion', 'mutual benefit', 'unclassified'.</param>
/// <param name="page">The page to return. This endpoint is paginated, and returns up to 30 nonprofits at a time.</param>
/// <param name="token"></param>
/// <returns>A paginated list of nonprofits.</returns>
Task<SearchNonprofitsResponse?> SearchAsync(
string name,
string[] categories,
int page = 1,
CancellationToken token = default);
/// <summary>
/// Immediately starts a payout to a nonprofit. Normally, nonprofits are paid once per month.
/// If you want a nonprofit to receive your donations sooner, use this endpoint. You will receive an invoice
/// for the donation funds within 24 hours of using this endpoint.
/// </summary>
/// <param name="id">The id of a nonprofit from the CHANGE network.</param>
/// <param name="token"></param>
/// <returns>The payout created</returns>
Task<CreateInstantPayoutResponse?> CreateInstantPayoutAsync(string id, CancellationToken token = default);

/// <summary>
/// Immediately starts a payout to a nonprofit. Normally, nonprofits are paid once per month.
/// If you want a nonprofit to receive your donations sooner, use this endpoint. You will receive an invoice
/// for the donation funds within 24 hours of using this endpoint.
/// </summary>
/// <param name="id">The id of a nonprofit from the CHANGE network.</param>
/// <param name="token"></param>
/// <returns>The payout created</returns>
Task<CreateInstantPayoutResponse?> CreateInstantPayoutAsync(string id, CancellationToken token = default);
/// <summary>
/// Retrieves a list of instant payouts you've previously made that are either pending or complete for the
/// last month. The instant payouts are returned in order of creation, with the most recent instant payouts
/// appearing first.
/// </summary>
/// <param name="id">The id of a nonprofit from the CHANGE network.</param>
/// <param name="token"></param>
/// <returns>A list of instant payouts you've previously made</returns>
Task<GetInstantPayoutsResponse?> GetInstantPayoutsAsync(string id, CancellationToken token = default);

/// <summary>
/// Retrieves a list of instant payouts you've previously made that are either pending or complete for the
/// last month. The instant payouts are returned in order of creation, with the most recent instant payouts
/// appearing first.
/// </summary>
/// <param name="id">The id of a nonprofit from the CHANGE network.</param>
/// <param name="token"></param>
/// <returns>A list of instant payouts you've previously made</returns>
Task<GetInstantPayoutsResponse?> GetInstantPayoutsAsync(string id, CancellationToken token = default);
}
/// <summary>
/// Requests a nonprofit.
/// </summary>
/// <param name="request">The create non-profit request.</param>
/// <param name="token"></param>
/// <returns>A list of instant payouts you've previously made</returns>
Task<CreateNonprofitResponse?> CreateNonprofitAsync(CreateNonprofitRequest request, CancellationToken token = default);
}
41 changes: 20 additions & 21 deletions Rest.GetChangeio.Abstractions/IPaymentsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
using Rest.GetChangeio.Requests;
using Rest.GetChangeio.ServiceModel;

namespace Rest.GetChangeio.Abstractions
namespace Rest.GetChangeio.Abstractions;

public interface IPaymentsService
{
public interface IPaymentsService
{
/// <summary>
/// Creates a Stripe Checkout link to collect donations for a specific nonprofit.
/// Donation processing fees are automatically deducted from the collected amount.
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Checkout?> CreateCheckoutAsync(CreateCheckoutRequest request, CancellationToken token = default);
/// <summary>
/// Creates a Stripe Checkout link to collect donations for a specific nonprofit.
/// Donation processing fees are automatically deducted from the collected amount.
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Checkout?> CreateCheckoutAsync(CreateCheckoutRequest request, CancellationToken token = default);

/// <summary>
/// Creates a Coinbase Checkout link to collect donations for a specific nonprofit. Donation processing fees
/// are automatically deducted from the collected amount. Accepted currencies include Bitcoin, Bitcoin Cash,
/// Dai, Dogecoin, Ethereum, Litecoin, and USD Coin.
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Checkout?> CreateCryptoCheckoutAsync(CreateCryptoCheckoutRequest request, CancellationToken token = default);
}
/// <summary>
/// Creates a Coinbase Checkout link to collect donations for a specific nonprofit. Donation processing fees
/// are automatically deducted from the collected amount. Accepted currencies include Bitcoin, Bitcoin Cash,
/// Dai, Dogecoin, Ethereum, Litecoin, and USD Coin.
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Checkout?> CreateCryptoCheckoutAsync(CreateCryptoCheckoutRequest request, CancellationToken token = default);
}
9 changes: 9 additions & 0 deletions Rest.GetChangeio.Enums/Rest.GetChangeio.Enums.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions Rest.GetChangeio.Enums/SocialType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Text.Json.Serialization;

namespace Rest.GetChangeio.Enums;


[JsonConverter(typeof(JsonStringEnumConverter))]
public enum SocialType
{
Facebook,
Instagram,
TikTok,
Twitter,
YouTube
}
37 changes: 18 additions & 19 deletions Rest.GetChangeio.Requests/CreateCheckoutRequest.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using System.Text.Json.Serialization;

namespace Rest.GetChangeio.Requests
{
/// <summary>
/// Creates a Stripe Checkout link to collect donations for a specific nonprofit.
/// Donation processing fees are automatically deducted from the collected amount.
/// </summary>
/// <param name="Amount">The amount of the donation in cents.</param>
/// <param name="NonprofitId">The id of a nonprofit from the Change network.</param>
/// <param name="SuccessUrl">The url the donor will be redirected to upon a successful donation.</param>
/// <param name="CancelUrl">The url the donor will be redirected to if they cancel checkout.</param>
public record CreateCheckoutRequest(
long Amount,
namespace Rest.GetChangeio.Requests;

[property: JsonPropertyName("nonprofit_id")]
string NonprofitId,
/// <summary>
/// Creates a Stripe Checkout link to collect donations for a specific nonprofit.
/// Donation processing fees are automatically deducted from the collected amount.
/// </summary>
/// <param name="Amount">The amount of the donation in cents.</param>
/// <param name="NonprofitId">The id of a nonprofit from the Change network.</param>
/// <param name="SuccessUrl">The url the donor will be redirected to upon a successful donation.</param>
/// <param name="CancelUrl">The url the donor will be redirected to if they cancel checkout.</param>
public record CreateCheckoutRequest(
long Amount,

[property: JsonPropertyName("success_url")]
string SuccessUrl,
[property: JsonPropertyName("nonprofit_id")]
string NonprofitId,

[property: JsonPropertyName("cancel_url")]
string CancelUrl);
}
[property: JsonPropertyName("success_url")]
string SuccessUrl,

[property: JsonPropertyName("cancel_url")]
string CancelUrl);
33 changes: 16 additions & 17 deletions Rest.GetChangeio.Requests/CreateCryptoCheckoutRequest.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Rest.GetChangeio.Requests
namespace Rest.GetChangeio.Requests;

/// <summary>
/// Creates a Stripe Checkout link to collect donations for a specific nonprofit.
/// Donation processing fees are automatically deducted from the collected amount.
/// </summary>
/// <param name="Amount">The amount of the donation in cents.</param>
/// <param name="NonprofitId">The id of a nonprofit from the Change network.</param>
public record CreateCryptoCheckoutRequest(
long Amount,

[property: JsonPropertyName("nonprofit_id")]
string NonprofitId)
{
/// <summary>
/// Creates a Stripe Checkout link to collect donations for a specific nonprofit.
/// Donation processing fees are automatically deducted from the collected amount.
/// A set of key-value pairs that you can attach to a donation.
/// This information will be returned in a webhook upon successful payment.
/// </summary>
/// <param name="Amount">The amount of the donation in cents.</param>
/// <param name="NonprofitId">The id of a nonprofit from the Change network.</param>
public record CreateCryptoCheckoutRequest(
long Amount,

[property: JsonPropertyName("nonprofit_id")]
string NonprofitId)
{
/// <summary>
/// A set of key-value pairs that you can attach to a donation.
/// This information will be returned in a webhook upon successful payment.
/// </summary>
public Dictionary<string, string>? Metadata { get; set; }
}
public Dictionary<string, string>? Metadata { get; set; }
}

0 comments on commit 153d286

Please sign in to comment.