Charges
Charges represent a payment processed given a customer's payment source, such as a credit card or bank account.
Charge Object
Attributes
{
"amount": 2000,
"amount_refunded": 0,
"created_at": 1607152637,
"currency": "usd",
"customer": 401558,
"disputed": false,
"failure_message": null,
"gateway": "test",
"gateway_id": "5d9e31d812151",
"id": 46374,
"payment_source": {
"brand": "Visa",
"chargeable": true,
"created_at": 1601919571,
"exp_month": 8,
"exp_year": 2025,
"failure_reason": null,
"funding": "credit",
"gateway": null,
"gateway_customer": null,
"gateway_id": null,
"id": 448165,
"last4": "8550",
"merchant_account": 2353,
"object": "card",
"receipt_email": null,
"updated_at": 1601919571
},
"receipt_email": null,
"refunded": false,
"refunds": [],
"status": "succeeded",
"updated_at": 1607152637
}
Parameter | Type | Description |
---|---|---|
id | integer | The charge's unique ID |
object | string | Object type, charge |
customer | integer | Associated Customer |
currency | string | 3-letter ISO code |
amount | number | Charge amount |
test | string | Payment test on which payment was processed |
gateway_id | string | Transaction ID on payment test |
status | string | Transaction status on payment test |
receipt_email | string | Email address where receipt was sent |
failure_message | string | Failure reason if charge fails |
payment_source | object | Payment Source that was used |
amount_refunded | number | Total amount refunded |
refunded | boolean | True if fully refunded |
refunds | array | List of Refunds |
disputed | boolean | True if charge has been disputed |
created_at | timestamp | Timestamp when created |
updated_at | timestamp | Timestamp when updated |
Create a charge
# (Tokenized Payment Info)
curl 'https://api.invoiced.com/charges' \
-u API_KEY: \
--data '{"customer":401558,"currency":"usd","amount":2000,"applied_to":[{"type":"invoice","invoice":2112620,"amount":1710},{"type":"invoice","invoice":2112622,"amount":290}],"method":"credit_card","invoiced_token":"acdf7f31da641970cdb9c6c46a373577"}'
# (Saved Payment Source)
curl 'https://api.invoiced.com/charges' \
-u API_KEY: \
--data '{"customer":401558,"currency":"usd","amount":2000,"applied_to":[{"type":"invoice","invoice":2112620,"amount":1710},{"type":"invoice","invoice":2112622,"amount":290}],"method":"credit_card","payment_source_type":"card","payment_source_id":1234}'
invoiced.Charge.create(
:customer => 401558,
:currency => "usd",
:amount => 2000,
:applied_to => [
{
:type => "invoice",
:invoice => 2112620,
:amount => 1710
},
{
:type => "invoice",
:invoice => 2112622,
:amount => 290
}
],
:method => "credit_card",
# (Tokenized Payment Info)
:invoiced_token => "acdf7f31da641970cdb9c6c46a373577",
# (Saved Payment Source)
:payment_source_type => "card",
:payment_source_id => 1234
)
<?php
$charge = $invoiced->Charge->create([
'customer' => 401558,
'currency' => "usd",
'amount' => 2000,
'applied_to' => [
[
'type' => 'invoice',
'invoice' => 2112620,
'amount' => 1710
],
[
'type' => 'invoice',
'invoice' => 2112622,
'amount' => 290
],
],
'method' => "credit_card",
// (Tokenized Payment Info)
'invoiced_token' => "acdf7f31da641970cdb9c6c46a373577",
// (Saved Payment Source)
'payment_source_type' => "card",
'payment_source_id' => 1234
]);
client.Charge.create(
customer = 401558,
currency = "usd",
amount = 2000,
applied_to = [
{
'type': 'invoice',
'invoice': 2112620,
'amount': 1710
},
{
'type': 'invoice',
'invoice': 2112622,
'amount': 290
},
],
method = "credit_card",
# (Tokenized Payment Info)
invoiced_token = "acdf7f31da641970cdb9c6c46a373577",
# (Saved Payment Source)
payment_source_type = "card",
payment_source_id = 1234
)
ChargeRequest chargeRequest = new ChargeRequest();
chargeRequest.customer = 401558L;
chargeRequest.currency = "usd";
chargeRequest.amount = 2000D;
paymentItem1 = new PaymentItem();
paymentItem1.type = "invoice";
paymentItem1.invoice = 2112620L;
paymentItem1.amount = 1710D;
paymentItem2 = new PaymentItem();
paymentItem2.type = "invoice";
paymentItem2.invoice = 2112622L;
paymentItem2.amount = 290D;
chargeRequest.appliedTo = PaymentItem{paymentItem1, paymentItem2};
chargeRequest.method = "credit_card";
// (Tokenized Payment Info)
chargeRequest.invoicedToken = "acdf7f31da641970cdb9c6c46a373577";
// (Saved Payment Source)
chargeRequest.paymentSourceType = "card";
chargeRequest.paymentSourceId = 1234;
Charge charge = invoiced.newCharge().create(chargeRequest);
var chargeRequest = new ChargeRequest();
chargeRequest.Customer = 401558;
chargeRequest.Currency = "usd";
chargeRequest.Amount = 2000;
chargeRequest.AppliedTo = new[]
{
new PaymentItem {Type = "invoice", Amount = 1710, Invoice = 2112620},
new PaymentItem {Type = "invoice", Amount = 290, Invoice = 2112622}
};
chargeRequest.Method = "credit_card";
// (Tokenized Payment Info)
chargeRequest.InvoicedToken = "acdf7f31da641970cdb9c6c46a373577";
// (Saved Payment Source)
chargeRequest.PaymentSourceType = "card";
chargeRequest.PaymentSourceId = 1234;
var charge = invoiced.NewCharge().Create(chargeRequest);
chargeRequest := new(invdendpoint.ChargeRequest)
charge, err := client.Charge.Create(&invoiced.ChargeRequest{
Customer: invoiced.Int64(401558),
Currency: invoiced.String("usd"),
Amount: invoiced.Float64(2000),
AppliedTo: []*invoiced.PaymentItemRequest{
{
Type: invoiced.String("invoice"),
Amount: invoiced.Float64(1710),
Invoice: invoiced.Int64(2112620),
},
{
Type: invoiced.String("invoice"),
Amount: invoiced.Float64(290),
Invoice: invoiced.Int64(2112622),
},
},
Method: invoiced.String("credit_card"),
// (Tokenized Payment Info)
InvoicedToken: invoiced.String("acdf7f31da641970cdb9c6c46a373577"),
// (Saved Payment Source)
PaymentSourceType: invoiced.String("card"),
PaymentSourceId: invoiced.Int64(1234),
})
The above command returns JSON structured like this:
{
"ach_sender_id": null,
"amount": 2000,
"balance": 0,
"charge": {
"amount": 2000,
"amount_refunded": 0,
"created_at": 1607152637,
"currency": "usd",
"customer": 401558,
"disputed": false,
"failure_message": null,
"gateway": "test",
"gateway_id": "5d9e31d812151",
"id": 46374,
"payment_source": {
"brand": "Visa",
"chargeable": true,
"created_at": 1601919571,
"exp_month": 8,
"exp_year": 2025,
"failure_reason": null,
"funding": "credit",
"gateway": null,
"gateway_customer": null,
"gateway_id": null,
"id": 448165,
"last4": "8550",
"merchant_account": 2353,
"object": "card",
"receipt_email": null,
"updated_at": 1601919571
},
"receipt_email": null,
"refunded": false,
"refunds": [],
"status": "succeeded",
"updated_at": 1607152637
},
"created_at": 1607152637,
"currency": "usd",
"customer": 401558,
"date": 1607152637,
"id": 32554,
"matched": null,
"method": "credit_card",
"notes": null,
"object": "payment",
"pdf_url": "https://dundermifflin.invoiced.com/payments/dPf17GiBjJYqcl0zjm7jc02a/pdf",
"reference": "5d9e31d812151",
"source": "api",
"updated_at": 1607152637,
"voided": false
}
This endpoint allows you to process a payment.
HTTP Request
POST /charges
Attributes
Requests must supply exactly one of a) payment_source_type
with payment_source_id
, b) invoiced_token
, or c) gateway_token
.
Parameter | Type | Description |
---|---|---|
customer | integer | Customer ID, required |
method | string | Required, one of credit_card or ach |
currency | string | Optional, defaults to company currency |
amount | number | Charge amount, required |
invoiced_token | string | Optional, generated by invoiced.js |
gateway_token | string | Optional, generated by payment test |
payment_source_type | string | One of card , bank_account |
payment_source_id | number | Optional, card or bank account ID |
vault_method | boolean | Optional; when true, vaults the payment source on the customer's account |
make_default | boolean | Optional; when this and vault_method are true, saves payment as default on customer's account |
receipt_email | string | Optional; where the payment receipt is sent |
applied_to | array | Required, List of Payment Applications |