Пример #1
0
        /// <summary>
        /// Make a swish payment via the m-commerce flow
        /// </summary>
        /// <param name="payment">The payment details</param>
        /// <returns>Payment response containing payment status location</returns>
        public async Task <MCommercePaymentResponse> MakeMCommercePaymentAsync(MCommercePaymentModel payment)
        {
            payment.PayeeAlias = MerchantId;
            var response = await Post(payment, _paymentRequestsPath).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.StatusCode == HttpStatusCode.Created)
            {
                return(ExtractMCommerceResponse(response));
            }
            return(GetErrorResponse <MCommercePaymentResponse>(responseContent, response.StatusCode));
        }
Пример #2
0
        /// <summary>
        /// Make a swish payment via the m-commerce flow
        /// </summary>
        /// <param name="payment">The payment details</param>
        /// <returns>Payment response containing payment status location</returns>
        public async Task <MCommercePaymentResponse> MakeMCommercePaymentAsync(MCommercePaymentModel payment)
        {
            payment.PayeeAlias = MerchantId;
            var response = await Post(payment, _paymentRequestsPath).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.StatusCode == (HttpStatusCode)422)
            {
                throw new HttpRequestException(responseContent);
            }

            /*
             * Potential Http status codes returned:
             * 201 Created: Returned when Payment request was successfully created. Will return a Location header and if it is Swish m-commerce case, it will also return PaymentRequestToken header.
             * 400 Bad Request: Returned when the Create Payment Request operation was malformed.
             * 401 Unauthorized: Returned when there are authentication problems with the certificate. Or the Swish number in the certificate is not enrolled. Will return nothing else.
             * 403 Forbidden: Returned when the payeeAlias in the payment request object is not the same as merchant’s Swish number.
             * 415 Unsupported Media Type: Returned when Content-Type header is not “application/json”. Will return nothing else.
             * 422 Unprocessable Entity: Returned when there are validation errors. Will return an Array of Error Objects.
             * 500 Internal Server Error: Returned if there was some unknown/unforeseen error that occurred on the server, this should normally not happen. Will return nothing else.
             * Potential Error codes returned on Error Objects when validation fails (HTTP status code 422 is returned):
             * FF08 – PaymentReference is invalid
             * RP03 – Callback URL is missing or does not use Https
             * BE18 – Payer alias is invalid
             * RP01 – Missing Merchant Swish Number
             * PA02 – Amount value is missing or not a valid number
             * AM06 – Specified transaction amount is less than agreed minimum
             * AM02 – Amount value is too large
             * AM03 – Invalid or missing Currency
             * RP02 – Wrong formated message
             * RP06 – A payment request already exist for that payer. Only applicable for Swish ecommerce.
             * ACMT03 – Payer not Enrolled
             * ACMT01 – Counterpart is not activated
             * ACMT07 – Payee not Enrolled
             */
            // TODO: handle error codes like in the GetPaymentStatus(...) method

            response.EnsureSuccessStatusCode();

            return(ExtractMCommerceResponse(response));
        }