public AmazonPayApiData ParseNotification(HttpRequestBase request) { string json = null; using (var reader = new StreamReader(request.InputStream)) { json = reader.ReadToEnd(); } var parser = new OffAmazonPaymentsNotifications.NotificationsParser(); var message = parser.ParseRawMessage(request.Headers, json); var data = new AmazonPayApiData() { MessageType = message.NotificationType.ToString(), MessageId = ((OffAmazonPaymentsNotifications.IpnNotificationMetadata)message.NotificationMetadata).NotificationReferenceId }; if (message.NotificationType == OffAmazonPaymentsNotifications.NotificationType.AuthorizationNotification) { var details = ((OffAmazonPaymentsNotifications.AuthorizationNotification)message).AuthorizationDetails; data.AuthorizationId = details.AmazonAuthorizationId; data.CaptureId = details.IdList.SafeGet(0); data.ReferenceId = details.AuthorizationReferenceId; data.CaptureNow = details.CaptureNow; data.Creation = details.CreationTimestamp; if (details.AuthorizationFee != null) { data.Fee = new AmazonPayApiPrice(details.AuthorizationFee.Amount, details.AuthorizationFee.CurrencyCode); } if (details.AuthorizationAmount != null) { data.AuthorizedAmount = new AmazonPayApiPrice(details.AuthorizationAmount.Amount, details.AuthorizationAmount.CurrencyCode); } if (details.CapturedAmount != null) { data.CapturedAmount = new AmazonPayApiPrice(details.CapturedAmount.Amount, details.CapturedAmount.CurrencyCode); } if (details.ExpirationTimestampSpecified) { data.Expiration = details.ExpirationTimestamp; } if (details.AuthorizationStatus != null) { data.ReasonCode = details.AuthorizationStatus.ReasonCode; data.ReasonDescription = details.AuthorizationStatus.ReasonDescription; data.State = details.AuthorizationStatus.State; data.StateLastUpdate = details.AuthorizationStatus.LastUpdateTimestamp; } } else if (message.NotificationType == OffAmazonPaymentsNotifications.NotificationType.CaptureNotification) { var details = ((OffAmazonPaymentsNotifications.CaptureNotification)message).CaptureDetails; data.CaptureId = details.AmazonCaptureId; data.ReferenceId = details.CaptureReferenceId; data.Creation = details.CreationTimestamp; if (details.CaptureFee != null) { data.Fee = new AmazonPayApiPrice(details.CaptureFee.Amount, details.CaptureFee.CurrencyCode); } if (details.CaptureAmount != null) { data.CapturedAmount = new AmazonPayApiPrice(details.CaptureAmount.Amount, details.CaptureAmount.CurrencyCode); } if (details.RefundedAmount != null) { data.RefundedAmount = new AmazonPayApiPrice(details.RefundedAmount.Amount, details.RefundedAmount.CurrencyCode); } if (details.CaptureStatus != null) { data.ReasonCode = details.CaptureStatus.ReasonCode; data.ReasonDescription = details.CaptureStatus.ReasonDescription; data.State = details.CaptureStatus.State; data.StateLastUpdate = details.CaptureStatus.LastUpdateTimestamp; } } else if (message.NotificationType == OffAmazonPaymentsNotifications.NotificationType.RefundNotification) { var details = ((OffAmazonPaymentsNotifications.RefundNotification)message).RefundDetails; data.RefundId = details.AmazonRefundId; data.ReferenceId = details.RefundReferenceId; data.Creation = details.CreationTimestamp; if (details.FeeRefunded != null) { data.Fee = new AmazonPayApiPrice(details.FeeRefunded.Amount, details.FeeRefunded.CurrencyCode); } if (details.RefundAmount != null) { data.RefundedAmount = new AmazonPayApiPrice(details.RefundAmount.Amount, details.RefundAmount.CurrencyCode); } if (details.RefundStatus != null) { data.ReasonCode = details.RefundStatus.ReasonCode; data.ReasonDescription = details.RefundStatus.ReasonDescription; data.State = details.RefundStatus.State; data.StateLastUpdate = details.RefundStatus.LastUpdateTimestamp; } } return(data); }
public AmazonPayApiData ParseNotification(HttpRequestBase request) { string json = null; using (var reader = new StreamReader(request.InputStream)) { json = reader.ReadToEnd(); } var parser = new OffAmazonPaymentsNotifications.NotificationsParser(); var message = parser.ParseRawMessage(request.Headers, json); var data = new AmazonPayApiData() { MessageType = message.NotificationType.ToString(), MessageId = ((OffAmazonPaymentsNotifications.IpnNotificationMetadata)message.NotificationMetadata).NotificationReferenceId }; if (message.NotificationType == OffAmazonPaymentsNotifications.NotificationType.AuthorizationNotification) { var details = ((OffAmazonPaymentsNotifications.AuthorizationNotification)message).AuthorizationDetails; data.AuthorizationId = details.AmazonAuthorizationId; data.CaptureId = details.IdList.SafeGet(0); data.ReferenceId = details.AuthorizationReferenceId; data.CaptureNow = details.CaptureNow; data.Creation = details.CreationTimestamp; if (details.AuthorizationFee != null) data.Fee = new AmazonPayApiPrice(details.AuthorizationFee.Amount, details.AuthorizationFee.CurrencyCode); if (details.AuthorizationAmount != null) data.AuthorizedAmount = new AmazonPayApiPrice(details.AuthorizationAmount.Amount, details.AuthorizationAmount.CurrencyCode); if (details.CapturedAmount != null) data.CapturedAmount = new AmazonPayApiPrice(details.CapturedAmount.Amount, details.CapturedAmount.CurrencyCode); if (details.ExpirationTimestampSpecified) data.Expiration = details.ExpirationTimestamp; if (details.AuthorizationStatus != null) { data.ReasonCode = details.AuthorizationStatus.ReasonCode; data.ReasonDescription = details.AuthorizationStatus.ReasonDescription; data.State = details.AuthorizationStatus.State; data.StateLastUpdate = details.AuthorizationStatus.LastUpdateTimestamp; } } else if (message.NotificationType == OffAmazonPaymentsNotifications.NotificationType.CaptureNotification) { var details = ((OffAmazonPaymentsNotifications.CaptureNotification)message).CaptureDetails; data.CaptureId = details.AmazonCaptureId; data.ReferenceId = details.CaptureReferenceId; data.Creation = details.CreationTimestamp; if (details.CaptureFee != null) data.Fee = new AmazonPayApiPrice(details.CaptureFee.Amount, details.CaptureFee.CurrencyCode); if (details.CaptureAmount != null) data.CapturedAmount = new AmazonPayApiPrice(details.CaptureAmount.Amount, details.CaptureAmount.CurrencyCode); if (details.RefundedAmount != null) data.RefundedAmount = new AmazonPayApiPrice(details.RefundedAmount.Amount, details.RefundedAmount.CurrencyCode); if (details.CaptureStatus != null) { data.ReasonCode = details.CaptureStatus.ReasonCode; data.ReasonDescription = details.CaptureStatus.ReasonDescription; data.State = details.CaptureStatus.State; data.StateLastUpdate = details.CaptureStatus.LastUpdateTimestamp; } } else if (message.NotificationType == OffAmazonPaymentsNotifications.NotificationType.RefundNotification) { var details = ((OffAmazonPaymentsNotifications.RefundNotification)message).RefundDetails; data.RefundId = details.AmazonRefundId; data.ReferenceId = details.RefundReferenceId; data.Creation = details.CreationTimestamp; if (details.FeeRefunded != null) data.Fee = new AmazonPayApiPrice(details.FeeRefunded.Amount, details.FeeRefunded.CurrencyCode); if (details.RefundAmount != null) data.RefundedAmount = new AmazonPayApiPrice(details.RefundAmount.Amount, details.RefundAmount.CurrencyCode); if (details.RefundStatus != null) { data.ReasonCode = details.RefundStatus.ReasonCode; data.ReasonDescription = details.RefundStatus.ReasonDescription; data.State = details.RefundStatus.State; data.StateLastUpdate = details.RefundStatus.LastUpdateTimestamp; } } return data; }