public void DeliveryApproval() { DeliveryApprovalRequest request = new DeliveryApprovalRequest() { ApiKey = "cab15d0f7d3247ca8e52e6d977576a4a", TransactionTime = ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(), TransactionId = "e69b90f919ec4994b3821d5c0add3f4e", BasketItemId = "1", EarnedAmount = 10, Version = "v1.0" }; DeliveryApprovalResponse deliveryApprovalResponse = _paymentProcessor.DeliveryApproval(request, WebConfigurationManager.AppSettings["ApiUrl"] + "/Payments/delivery-approval", "123"); deliveryApprovalResponse.TransactionId.Should().Be(request.TransactionId); deliveryApprovalResponse.MessageCode.Should().Be("0000"); }
protected virtual void ControlDeliveryApprovalResponseSignature(DeliveryApprovalResponse deliveryApprovalResponse, string secretKey, string version) { var transactionId = (!string.IsNullOrEmpty(deliveryApprovalResponse.TransactionId) ? deliveryApprovalResponse.TransactionId : String.Empty); var transactionTime = (!string.IsNullOrEmpty(deliveryApprovalResponse.TransactionTime) ? deliveryApprovalResponse.TransactionTime : String.Empty); var messageCode = deliveryApprovalResponse.MessageCode; var text = secretKey + transactionId + transactionTime + deliveryApprovalResponse.EarnedAmount + messageCode; string signature; if (version == "1.1") { signature = CryptographyHelper.HMacSha512(text, secretKey); } else { signature = CryptographyHelper.HashSha256(text); } if (signature != deliveryApprovalResponse.Signature) { throw new DpayClientException(Constants.SignatureVerificationError, Constants.SignatureVerificationError.ReturnErrorMessage(), Constants.SignatureVerificationError.ReturnUserErrorMessage()); } }
protected override void ControlDeliveryApprovalResponseSignature(DeliveryApprovalResponse deliveryApprovalResponse, string secretKey, string version) { }
public TestableDeliveryApprovalProcessor(DeliveryApprovalResponse deliveryApprovalResponse) { _deliveryApprovalResponse = deliveryApprovalResponse; }