QTarik Liverpool
QTarik Liverpool

Reputation: 11

How to execute this cUrl command with flutter?

I have the below cUrl command in PayPal payout

     curl -v -X POST https://api.sandbox.paypal.com/v1/payments/payouts \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer Access-Token" \
    -d '{
    "sender_batch_header": {
    "sender_batch_id": "2014021801",
    "email_subject": "You have a payout!",
    "email_message": "You have received a payout! Thanks for using our service!"
    },
    "items": [
    {
    "recipient_type": "EMAIL",
    "amount": {
      "value": "9.87",
      "currency": "USD"
      },

  "receiver": "[email protected]"
  },
  {
  "recipient_type": "PHONE",
  "amount": {
    "value": "112.34",
    "currency": "USD"
  },
  "note": "Thanks for your support!",
  "sender_item_id": "201403140002",
  "receiver": "91-734-234-1234"
  }, 

  ]
  }'

I wish to execute this cUrl command with flutter which contains a lot of parts. Thanks in Advance

Upvotes: 0

Views: 1937

Answers (1)

dubace
dubace

Reputation: 1621

You can use Dio library for sending requests, it's the most popular library now.

Try the next code, ofc with your Bearer Access-Token

  void send() async {
    final Map<String, String> headers = {
      HttpHeaders.contentTypeHeader: "application/json"
      HttpHeaders.authorizationHeader: "Bearer Access-Token"
    }
    response = await dio.post("https://api.sandbox.paypal.com/v1/payments/payouts",
      options: Options(
        headers: _headers
      )
      data: {
        "sender_batch_header": {
        "sender_batch_id": "2014021801",
        "email_subject": "You have a payout!",
        "email_message": "You have received a payout! Thanks for using our service!"
        },
        "items": [{
          "recipient_type": "EMAIL",
          "amount": {
            "value": "9.87",
            "currency": "USD"
          },
          "receiver": "[email protected]"
        },
        {
          "recipient_type": "PHONE",
          "amount": {
            "value": "112.34",
            "currency": "USD"
          },
          "note": "Thanks for your support!",
          "sender_item_id": "201403140002",
          "receiver": "91-734-234-1234"
        }]
      }
      );
  }

Upvotes: 1

Related Questions