Skip to content

Commit

Permalink
Add transaction status updated webhook (blacklightcms#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellagasta authored Aug 9, 2020
1 parent 3324468 commit 0c0179f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
13 changes: 7 additions & 6 deletions webhooks/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
// Payment notifications.
// https://dev.recurly.com/page/webhooks#payment-notifications
const (
SuccessfulPayment = "successful_payment_notification"
FailedPayment = "failed_payment_notification"
VoidPayment = "void_payment_notification"
SuccessfulRefund = "successful_refund_notification"
ScheduledPayment = "scheduled_payment_notification"
ProcessingPayment = "processing_payment_notification"
SuccessfulPayment = "successful_payment_notification"
FailedPayment = "failed_payment_notification"
VoidPayment = "void_payment_notification"
SuccessfulRefund = "successful_refund_notification"
ScheduledPayment = "scheduled_payment_notification"
ProcessingPayment = "processing_payment_notification"
TransactionStatusUpdated = "transaction_status_updated_notification"
)

// PaymentNotification is returned for all credit payment notifications.
Expand Down
31 changes: 31 additions & 0 deletions webhooks/testdata/transaction_status_updated_notification.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<transaction_status_updated_notification>
<account>
<account_code>1</account_code>
<username nil="true">verena</username>
<email>[email protected]</email>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<company_name nil="true">Company, Inc.</company_name>
</account>
<transaction>
<id>a5143c1d3a6f4a8287d0e2cc1d4c0427</id>
<invoice_id>ffc64d71d4b5404e93f13aac9c63b007</invoice_id>
<invoice_number type="integer">2059</invoice_number>
<subscription_id>1974a098jhlkjasdfljkha898326881c</subscription_id>
<action>purchase</action>
<date type="datetime">2010-10-05T23:00:50Z</date>
<amount_in_cents type="integer">1000</amount_in_cents>
<status>void</status>
<message>Test Gateway: Successful test transaction</message>
<reference>reference</reference>
<source>subscription</source>
<cvv_result code="" />
<avs_result code="" />
<avs_result_street />
<avs_result_postal />
<test type="boolean">true</test>
<voidable type="boolean">true</voidable>
<refundable type="boolean">true</refundable>
</transaction>
</transaction_status_updated_notification>
2 changes: 1 addition & 1 deletion webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func nameToNotification(name string) (interface{}, error) {
return &CreditInvoiceNotification{Type: name}, nil
case NewCreditPayment, VoidedCreditPayment:
return &CreditPaymentNotification{Type: name}, nil
case SuccessfulPayment, FailedPayment, VoidPayment, SuccessfulRefund, ScheduledPayment, ProcessingPayment:
case SuccessfulPayment, FailedPayment, VoidPayment, SuccessfulRefund, ScheduledPayment, ProcessingPayment, TransactionStatusUpdated:
return &PaymentNotification{Type: name}, nil
case NewDunningEvent:
return &NewDunningEventNotification{Type: name}, nil
Expand Down
35 changes: 35 additions & 0 deletions webhooks/webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,41 @@ func TestParse_ScheduledPaymentNotification(t *testing.T) {
}
}

func TestParse_TransactionStatusUpdatedNotification(t *testing.T) {
result := MustParseFile("testdata/transaction_status_updated_notification.xml")
if n, ok := result.(*webhooks.PaymentNotification); !ok {
t.Fatalf("unexpected type: %T, result", n)
} else if diff := cmp.Diff(n, &webhooks.PaymentNotification{
Type: webhooks.TransactionStatusUpdated,
Account: webhooks.Account{
XMLName: xml.Name{Local: "account"},
Code: "1",
Username: "verena",
Email: "[email protected]",
FirstName: "Verena",
LastName: "Example",
CompanyName: "Company, Inc.",
},
Transaction: webhooks.Transaction{
XMLName: xml.Name{Local: "transaction"},
UUID: "a5143c1d3a6f4a8287d0e2cc1d4c0427",
InvoiceNumber: 2059,
SubscriptionUUID: "1974a098jhlkjasdfljkha898326881c",
Action: "purchase",
AmountInCents: 1000,
Status: "void",
Message: "Test Gateway: Successful test transaction",
Reference: "reference",
Source: "subscription",
Test: recurly.NewBool(true),
Voidable: recurly.NewBool(true),
Refundable: recurly.NewBool(true),
},
}); diff != "" {
t.Fatal(diff)
}
}

func TestParse_NewDunningEventNotification(t *testing.T) {
result := MustParseFile("testdata/new_dunning_event_notification.xml")
if n, ok := result.(*webhooks.NewDunningEventNotification); !ok {
Expand Down

0 comments on commit 0c0179f

Please sign in to comment.