Ionic 3 Axios Library Usage

16-07-2017
import * as queryString from 'querystring';

async send(order) {
    const response = await axios.post('/isbank/send', queryString.stringify(
    {
        orderNo: order.orderNo,
        amount: order.amount,
        currencyCode: '949',
        language: 'tr',
        'creditCard.cardType': '1',
        'creditCard.cv2': order.cvc,
        'creditCard.expiredMonth': order.expiredMonth,
        'creditCard.expiredYear': order.expiredYear,
        'creditCard.pan': order.number,
        'user.Email': order.email,
        'user.Id': order.userId
        }))
        .then((response) => {
            return response.data;
        });
        return response;
    }

Normally, axios requests are json based, but if you want to send request classic form based use querystring library which is imported at line 1

Notice that at line 1, async keyword is used before function name, and await keyword is used before axios.post method at line 2.

Also at line 2, we should use constant variable, so const keyword is used.

send() function call:

const result = await  send(order);

© 2019 All rights reserved. Codesenior.COM