Examples

Refund a payment to credit card

Refund of credit card payments have a faster response, however, it's important to remember that the time period for the refund to be reflected in the customer's invoice may depend on the issuer's policies on the card.

Refunds of payments made by credit card will be made directly on the same credit card used by the customer/buyer.

Through this API you can send the request for Refund .

/*
For credit card refunds, simply insert the PAY code at the endpoint
http://www.sandbox.moip.com.br/v2/payments/{payment_id}/refunds

Use the POST method

Note: If you want to make a partial refund, you must enter the amount attribute in the body of the request. Example:

{
"amount": 2000
}

*/
#
# This example is based in our SDK developed in Ruby, available
# on: https://github.com/wirecardBrasil/moip-sdk-ruby
#

refund = api.refund.create("PAY-HL7QRKFEQNHV")
<?php

/**
* This example is based in our SDK developed in PHP, available
* on: https://github.com/wirecardBrasil/moip-sdk-php
*/

$payment = $moip->payments()->get("PAYMENT_ID");

$refund = $payment->refunds()->creditCardFull();

print_r($refund);
/**
* This example is based in our SDK developed in Java, available
* on: https://github.com/wirecardBrasil/moip-sdk-java
*/

Map<String, Object> newRefund = Moip.API.refunds().refundPayment("payment_id", setup);
var body = new RefundRequest
{
    Amount = "2000"
};            
var result = await WC.Refund.RefundPayment(body, "PAY-XXXXXXXXXXXX");
/**
* This example is based in our SDK developed in Node js, available
* on: https://github.com/wirecardBrasil/moip-sdk-node
*/

const moip = require('moip-sdk-node').default({
  accessToken: 'your-access-token',
  production: false
})

moip.payment.refund('PAY-3GALBSZIUSBE')
    .then((response) => {
        console.log(response)
    }).catch((err) => {
        console.log(err)
    })
curl -v https://sandbox.moip.com.br/v2/payments/{payment_id}/refunds \
   -H 'Content-Type: application/json'  \
   -H 'Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQg==' \
   -d '{}'

Refund a payment to bank account

If you prefer to refund the buyer through a bank account, this process is possible. However, the destination account must be of the same ownership as the buyer. Remember to check this information! :)

Through this API you can send the request for Refund .

{
  "refundingInstrument": {
    "method": "BANK_ACCOUNT",
    "bankAccount": {
      "type": "CHECKING",
      "bankNumber": "001",
      "agencyNumber": 4444444,
      "agencyCheckNumber": 2,
      "accountNumber": 1234,
      "accountCheckNumber": 1,
      "holder": {
        "fullname": "Jose Silva",
        "taxDocument": {
          "type": "CPF",
          "number": "22222222222"
        }
      }
    }
  }
}
#
# This example is based in our SDK developed in Ruby, available
# on: https://github.com/wirecardBrasil/moip-sdk-ruby
#

boleto_refund = api.refund.create(
  "PAY-YCORW3ZIYYXD", refundingInstrument: {
    method: "BANK_ACCOUNT",
    bankAccount: {
      bankNumber: "001",
      agencyNumber: "4444444",
      agencyCheckNumber: "2",
      accountNumber: "1234",
      accountCheckNumber: "1",
      type: "CHECKING",
      holder: {
        fullname: "Jose Silva",
        taxDocument: {
          type: "CPF",
          number: "22222222222",
        }
      }
    }
  }
)
<?php

/**
* This example is based in our SDK developed in PHP, available
* on: https://github.com/wirecardBrasil/moip-sdk-php
*/

$holder = $moip->customers()->get("CUS-87HFA3QCEKO7");
$payment = $moip->payments()->get("PAY-YCORW3ZIYYXD");

//Dados da conta bancária
$type = 'CHECKING';
$bank_number = '001';
$agency_number = 4444444;
$agency_check_number = 2;
$account_number = 1234;
$account_check_number = 1;

$refund = $payment->refunds()
    ->bankAccountFull($type, $bank_number, $agency_number, $agency_check_number, 
        $account_number, $account_check_number, $holder);

print_r($refund);
/**
* This example is based in our SDK developed in Java, available
* on: https://github.com/wirecardBrasil/moip-sdk-java
*/

Map<String, Object> taxDocument = payloadFactory(
    value("type", "CPF"),
    value("number", "123.456.798-91")
);

Map<String, Object> holder = payloadFactory(
    value("fullname", "Jose Silva"),
    value("taxDocument", taxDocument)
);

Map<String, Object> bankAccount = payloadFactory(
    value("type", "CHECKING"),
    value("bankNumber", "001"),
    value("agencyNumber", 4444444),
    value("agencyCheckNumber", 2),
    value("accountNumber", 1234),
    value("accountCheckNumber", 1),
    value("holder", holder)
);

Map<String, Object> refundingInstrument = payloadFactory(
    value("method", "BANK_ACCOUNT"),
    value("bankAccount", bankAccount)
);

Map<String, Object> refundBankAccount = payloadFactory(
    value("refundingInstrument", refundingInstrument)
);

Map<String, Object> newRefund = Moip.API.refunds().refundPayment(refundBankAccount, "payment_id", setup);
/**
* This example is based in our SDK developed in Node js, available
* on: https://github.com/wirecardBrasil/moip-sdk-node
*/

moip.payment.refunds.create('PAY-3GALBSZIUSBE',
    refundingInstrument: {
    method: "BANK_ACCOUNT",
    bankAccount: {
      bankNumber: "001",
      agencyNumber: "4444444",
      agencyCheckNumber: "2",
      accountNumber: "1234",
      accountCheckNumber: "1",
      type: "CHECKING",
      holder: {
        fullname: "Jose Silva",
        taxDocument: {
          type: "CPF",
          number: "22222222222",
        }
      }
    }
  }).then((response) => {
        console.log(response)
    }).catch((err) => {
        console.log(err)
    })

Refund a payment to wirecard account

{  
   "refundingInstrument":{  
      "method":"MOIP_ACCOUNT",
      "moipAccount":{  
         "id":"MPA-82B8D2ND923D"
      }
   }
}
/**
* This example is based in our SDK developed in Java, available
* on: https://github.com/wirecardBrasil/moip-sdk-java
*/

Map<String, Object> moipAccount = payloadFactory(
    value("id", "moip_account_id")
);

Map<String, Object> refundingInstrument = payloadFactory(
    value("method", "MOIP_ACCOUNT"),
    value("moipAccount", moipAccount)
);

Map<String, Object> refundMoipAccount = payloadFactory(
    value("amount", "500"),
    value("refundingInstrument", refundingInstrument)
);

Map<String, Object> newRefund = Moip.API.refunds().refundPayment(refundMoipAccount, "payment_id", setup);
#
# This example is based in our SDK developed in Ruby, available
# on: https://github.com/wirecardBrasil/moip-sdk-ruby
#

payment_refund = api.refund.create(
  "PAY-YCORW3ZIYYXD", refundingInstrument: {
    method: "MOIP_ACCOUNT",
    moipAccount: {
      id: "MPA-82B8D2ND923D"
        }
        }
        )
/**
* This example is based in our SDK developed in Node js, available
* on: https://github.com/wirecardBrasil/moip-sdk-node
*/

moip.payment.refunds.create('PAY-3GALBSZIUSBE',
    refundingInstrument: {
    method: "MOIP_ACCOUNT",
    moipAccount: {
      id: "MPA-82B8D2ND923D"
        }
      }).then((response) => {
        console.log(response)
    }).catch((err) => {
        console.log(err)
    })

Refund an order to credit card

/*
For credit card refunds, simply insert the ORD code at the endpoint
http://www.sandbox.moip.com.br/v2/order/{order_id}/refunds

Use the POST method

Note: If you want to make a partial refund, you must enter the amount attribute in the body of the request. Example:

{
"amount": 2000
}

*/
#
# This example is based in our SDK developed in Ruby, available
# on: https://github.com/wirecardBrasil/moip-sdk-ruby
#

order_refund = api.refund.create("ORD-O5DLMAJZPTHV")
<?php

/**
* This example is based in our SDK developed in PHP, available
* on: https://github.com/wirecardBrasil/moip-sdk-php
*/

$order = $moip->orders()->get("ORDER_ID");
    
$refund = $order->refunds()->creditCardFull();

print_r($refund);
/**
* This example is based in our SDK developed in Java, available
* on: https://github.com/wirecardBrasil/moip-sdk-java
*/

Map<String, Object> newRefund = Moip.API.refunds().refundOrder("order_id", setup);
var body = new RefundRequest
{
    Amount = "2000"
};            
var result = await WC.Refund.RefundRequestCreditCard(body, "ORD-XXXXXXXXXXXX");
/**
* This example is based in our SDK developed in Node js, available
* on: https://github.com/wirecardBrasil/moip-sdk-node
*/

const moip = require('moip-sdk-node').default({
  accessToken: 'your-access-token',
  production: false
})

moip.order.refund('ORD-4GALBSZIUSBE')
    .then((response) => {
        console.log(response)
    }).catch((err) => {
        console.log(err)
    })
}
curl -v https://sandbox.moip.com.br/v2/orders/ORD-O5DLMAJZPTHV/refunds \
   -H 'Content-Type: application/json'  \
   -H 'Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQg==' \
   -d '{}'

Refund an order to bank account

{
  "refundingInstrument": {
    "method": "BANK_ACCOUNT",
    "bankAccount": {
      "type": "CHECKING",
      "bankNumber": "001",
      "agencyNumber": 4444444,
      "agencyCheckNumber": 2,
      "accountNumber": 1234,
      "accountCheckNumber": 1,
      "holder": {
        "fullname": "Jose Silva",
        "taxDocument": {
          "type": "CPF",
          "number": "22222222222"
        }
      }
    }
  }
}
#
# This example is based in our SDK developed in Ruby, available
# on: https://github.com/wirecardBrasil/moip-sdk-ruby
#

boleto_refund = api.refund.create(
  "ORD-HH6AV9VMKYWO", refundingInstrument: {
    method: "BANK_ACCOUNT",
    bankAccount: {
      bankNumber: "001",
      agencyNumber: "4444444",
      agencyCheckNumber: "2",
      accountNumber: "1234",
      accountCheckNumber: "1",
      type: "CHECKING",
      holder: {
        fullname: "Jose Silva",
        taxDocument: {
          type: "CPF",
          number: "22222222222",
        },
      },
    },
  }
)
<?php

/**
* This example is based in our SDK developed in PHP, available
* on: https://github.com/wirecardBrasil/moip-sdk-php
*/

$holder = $moip->customers()->get("CUSTOMER_ID");
$order = $moip->orders()->get("ORDER_ID");

$type = 'CHECKING';
$bank_number = '001';
$agency_number = 4444444;
$agency_check_number = 2;
$account_number = 1234;
$account_check_number = 1;
$refund = $order->refunds()
    ->bankAccountFull($type, $bank_number, $agency_number, $agency_check_number, 
        $account_number, $account_check_number, $holder);

print_r($refund);
/**
* This example is based in our SDK developed in Java, available
* on: https://github.com/wirecardBrasil/moip-sdk-java
*/

Map<String, Object> taxDocument = payloadFactory(
    value("type", "CPF"),
    value("number", "123.456.798-91")
);

Map<String, Object> holder = payloadFactory(
    value("fullname", "Jose Silva"),
    value("taxDocument", taxDocument)
);

Map<String, Object> bankAccount = payloadFactory(
    value("type", "CHECKING"),
    value("bankNumber", "001"),
    value("agencyNumber", 4444444),
    value("agencyCheckNumber", 2),
    value("accountNumber", 1234),
    value("accountCheckNumber", 1),
    value("holder", holder)
);

Map<String, Object> refundingInstrument = payloadFactory(
    value("method", "BANK_ACCOUNT"),
    value("bankAccount", bankAccount)
);

Map<String, Object> refundBankAccount = payloadFactory(
    value("refundingInstrument", refundingInstrument)
);

Map<String, Object> newRefund = Moip.API.refunds().refundOrder(refundBankAccount, "order_id", setup);
/**
* This example is based in our SDK developed in Node js, available
* on: https://github.com/wirecardBrasil/moip-sdk-node
*/

moip.order.refunds.create('ORD-4GALBSZIUSBE',
    refundingInstrument: {
    method: "BANK_ACCOUNT",
    bankAccount: {
      bankNumber: "001",
      agencyNumber: "4444444",
      agencyCheckNumber: "2",
      accountNumber: "1234",
      accountCheckNumber: "1",
      type: "CHECKING",
      holder: {
        fullname: "Jose Silva",
        taxDocument: {
          type: "CPF",
          number: "22222222222",
        }
      }
    }
  }).then((response) => {
        console.log(response)
    }).catch((err) => {
        console.log(err)
    })

Refund an order to wirecard account

{  
   "refundingInstrument":{  
      "method":"MOIP_ACCOUNT",
      "moipAccount":{  
         "id":"MPA-82B8D2ND923D"
      }
   }
}
/**
* This example is based in our SDK developed in Java, available
* on: https://github.com/wirecardBrasil/moip-sdk-java
*/

Map<String, Object> moipAccount = payloadFactory(
    value("id", "moip_account_id")
);

Map<String, Object> refundingInstrument = payloadFactory(
    value("method", "MOIP_ACCOUNT"),
    value("moipAccount", moipAccount)
);

Map<String, Object> refundMoipAccount = payloadFactory(
    value("amount", "500"),
    value("refundingInstrument", refundingInstrument)
);

Map<String, Object> newRefund = Moip.API.refunds().refundOrder(refundMoipAccount, "order_id", setup);
#
# This example is based in our SDK developed in Ruby, available
# on: https://github.com/wirecardBrasil/moip-sdk-ruby
#

payment_refund = api.refund.create(
  "ORD-YCORW3ZIYYXD", refundingInstrument: {
    method: "MOIP_ACCOUNT",
    moipAccount: {
      id: "MPA-82B8D2ND923D"
        }
        }
        )
/**
* This example is based in our SDK developed in Node js, available
* on: https://github.com/wirecardBrasil/moip-sdk-node
*/

moip.order.refunds.create('ORD-3GALBSZIUSBE',
    refundingInstrument: {
    method: "MOIP_ACCOUNT",
    moipAccount: {
      id: "MPA-82B8D2ND923D"
        }
      }).then((response) => {
        console.log(response)
    }).catch((err) => {
        console.log(err)
    })