Skip to content

Commit

Permalink
Add interval support for direct debits
Browse files Browse the repository at this point in the history
  • Loading branch information
base33 committed Sep 16, 2020
1 parent c0aed75 commit 3446119
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 3 deletions.
Binary file added deployment/Our.Umbraco.Cashier.1.0.2.nupkg
Binary file not shown.
Binary file added deployment/Our.Umbraco.Cashier.1.0.3.nupkg
Binary file not shown.
Binary file added deployment/Our.Umbraco.Cashier.Stripe.1.0.2.nupkg
Binary file not shown.
Binary file added deployment/Our.Umbraco.Cashier.Stripe.1.0.3.nupkg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected Models.PaymentIntent UpdatePaymentIntent(string sessionId)
return paymentIntent;
}

var ddPriceName = "Direct Debit - " + paymentIntent.Amount;
var ddPriceName = $"Direct Debit - {paymentIntent.DirectDebitFrequencyMonths} Month{(paymentIntent.DirectDebitFrequencyMonths > 1 ? "s" : "")} - {paymentIntent.Amount}";

var productService = new ProductService();
var product = productService.List().FirstOrDefault(p => p.Description == "Direct Debit");
Expand Down Expand Up @@ -142,6 +142,7 @@ protected Models.PaymentIntent UpdatePaymentIntent(string sessionId)
Recurring = new PriceRecurringOptions
{
Interval = "month",
IntervalCount = paymentIntent.DirectDebitFrequencyMonths,
UsageType = "licensed"
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public ActionResult HandleDonationForm(DonationFormModel model)
"a constituent ID",
model.Amount,
"gbp",
DateTime.UtcNow,
DateTime.UtcNow.AddHours(3),
3, //three months
"craig@mentordigital.co.uk",
"craig@mentordigital.co.uk",
new CustomerAddress { AddressLines = "Street", City= "Bristol", Country = "United Kingdom", Postcode = "BS13 2xs" },
Expand Down
1 change: 1 addition & 0 deletions src/Cashier/CashierService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public PaymentIntentCreated CreateNewPaymentIntent(PaymentIntentRequest request)
if (request.PaymentIntentType == PaymentIntentType.DirectDebit)
{
paymentIntent.DirectDebitStartDate = request.DirectDebitStartDate;
paymentIntent.DirectDebitFrequencyMonths = request.DirectDebitFrequencyMonths;
paymentIntent.CustomerAddressLines = request.CustomerAddress.AddressLines;
paymentIntent.CustomerCity = request.CustomerAddress.City;
paymentIntent.CustomerCountry = request.CustomerAddress.Country;
Expand Down
10 changes: 10 additions & 0 deletions src/Cashier/Data/PaymentIntentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ [CustomerUniqueReference] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
IF NOT EXISTS (
SELECT *
FROM sys.columns
WHERE object_id = OBJECT_ID(N'[dbo].[PaymentIntents]')
AND name = 'DirectDebitFrequencyMonths'
)
BEGIN
ALTER TABLE PaymentIntents
ADD [DirectDebitFrequencyMonths] INT
END
");
}
Expand Down
1 change: 1 addition & 0 deletions src/Cashier/Models/PaymentIntent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PaymentIntent
public DateTime Updated { get; set; } = DateTime.Now;
public string HandShake { get; set; }
public string CustomerUniqueReference { get; set; }
public int DirectDebitFrequencyMonths { get; set; }
}

public enum PaymentIntentType
Expand Down
4 changes: 3 additions & 1 deletion src/Cashier/Models/PaymentIntentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class PaymentIntentRequest
public string CallbackUrl { get; set; }
public string AdditionalData { get; set; }
public DateTime DirectDebitStartDate { get; set; }
public int DirectDebitFrequencyMonths { get; private set; }
public string CustomerEmail { get; set; }
public string CustomerUniqueReference { get; set; }
public CustomerAddress CustomerAddress { get; set; }
Expand All @@ -39,7 +40,7 @@ public static PaymentIntentRequest CreateCardPayment(string transactionReference
return pi;
}

public static PaymentIntentRequest CreateDirectDebit(string transactionReference, string description, double amount, string currency, DateTime directDebitStartDate, string customerEmail, string customerUniqueReference, CustomerAddress customerAddress, string confirmationPageUrl, string failurePageUrl, string callbackUrl, string additionalData)
public static PaymentIntentRequest CreateDirectDebit(string transactionReference, string description, double amount, string currency, DateTime directDebitStartDate, int directDebitFrequencyMonths, string customerEmail, string customerUniqueReference, CustomerAddress customerAddress, string confirmationPageUrl, string failurePageUrl, string callbackUrl, string additionalData)
{
var pi = new PaymentIntentRequest();
pi.PaymentIntentType = PaymentIntentType.DirectDebit;
Expand All @@ -48,6 +49,7 @@ public static PaymentIntentRequest CreateDirectDebit(string transactionReference
pi.TransactionReference = transactionReference;
pi.Description = description;
pi.DirectDebitStartDate = directDebitStartDate;
pi.DirectDebitFrequencyMonths = directDebitFrequencyMonths;
pi.CustomerEmail = customerEmail;
pi.CustomerUniqueReference = customerUniqueReference;
pi.CustomerAddress = customerAddress;
Expand Down

0 comments on commit 3446119

Please sign in to comment.