invoiceku-id / invoiceku-php-sdk
Invoiceku.id 集成 PHP SDK
Requires
- php: ^8.0|^8.1
- guzzlehttp/guzzle: ^7.0
- spatie/data-transfer-object: ^3.9
README
Invoiceku.id 集成 PHP SDK
安装
composer require invoiceku-id/invoiceku-php-sdk
使用方法
以下是使用 Invoiceku ID SDK 的方法:
设置配置
您必须先在此处创建 API 密钥 这里。创建 API 密钥后,您现在可以配置 Invoiceku SDK。
\InvoicekuId\InvoicekuPhpSdk\Config::$api_key="API KEY"
请确保在上面的代码中设置了初始化应用程序或想要对 Invoiceku 终端点进行请求时的配置。
数据处理
以下是此 SDK 可以获取的数据。在继续此步骤之前,请确保您已按照上面的说明配置了 API 密钥。
获取数据概要
new (\InvoicekuId\InvoicekuPhpSdk\Domains\Membership\Objects\User)->myProfile();
或者,
$user = new \InvoicekuId\InvoicekuPhpSdk\Domains\Membership\Objects\User;
$user->myProfile();
上面的代码将返回一个数组,其结构如下所示
[
"id" => 1,
"name" => "My Name",
"email" => "my_namen@example.org",
"phone" => "+18648474206",
"email_verified_at" => "2023-02-03T12:22:25.000000Z",
"is_data_verified" => 0,
"created_at" => "2023-02-03T12:22:25.000000Z",
"updated_at" => "2023-02-25T17:00:18.000000Z"
]
获取您的账户设置数据
new (\InvoicekuId\InvoicekuPhpSdk\Domains\Membership\Objects\User)->getSettings();
或者,
$user = new \InvoicekuId\InvoicekuPhpSdk\Domains\Membership\Objects\User;
$user->getSettings();
上面的代码将返回一个数组,其结构如下所示
[
"setting_1" => "value setting 1"
]
保存账户设置
use \InvoicekuId\InvoicekuPhpSdk\Domains\Membership\Data\SettingData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Membership\Objects\User;
/**
Data untuk value bisa berupa apapun seperti array, object, integer, string dan lain-lain.
**/
$setting_data = new SettingData([
"key" => "value"
]);
$user = new User;
$user->setSetting($setting_data);
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil setting data."
]
获取支付网关数据
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Payment\Objects\PaymentGateway)->get();
上面的代码中的 get 方法可以接受两个参数,即 integer
类型的 per_page
和 page
,因为端点采用了分页系统,所以您可以轻松地设置每次请求要显示多少数据。以下是如何使用 get 方法的示例:get(per_page:10,page:1)
上述代码的输出将是一个数组,如下所示
[
"current_page" => 1,
"data" => [
[
"name" => "BCA",
"vendor" => "Moota",
"meta" => [
"account_holder" => "Diki Akbar Asyidiq",
"account_number" => 4020374476,
"image_url" => "payment-gateways/5PyjExBBz64.png",
],
"is_active" => 0,
"is_pos" => 0,
"deleted_at" => null,
"created_at" => "2023-02-04T09:43:17.000000Z",
"updated_at" => "2023-02-17T17:15:08.000000Z",
"payment_gateway_id" => "l042zQGE",
],
[
"name" => "BCA",
"vendor" => "Offline",
"meta" => [
"image_url" => "Kr3qc5Z2y0wnLRSm65ECwXC3rBUUYc-metaNVB5akV4QkJ6NjQucG5n-.png",
"account_holder" => "Diki Akbar Asyidiq",
"account_number" => "4020374476",
],
"is_active" => 1,
"is_pos" => 0,
"deleted_at" => null,
"created_at" => "2023-02-04T12:18:49.000000Z",
"updated_at" => "2023-02-15T16:03:51.000000Z",
"payment_gateway_id" => "zn24JgvM",
]
],
"first_page_url" => "https://invoiceku.id/api/payment-gateway?page=1",
"from" => 1,
"last_page" => 1,
"last_page_url" => "https://invoiceku.id/api/payment-gateway?page=1",
"links" => [
[
"url" => null,
"label" => "« Sebelumnya",
"active" => false,
],
[
"url" => "https://invoiceku.id/api/payment-gateway?page=1",
"label" => "1",
"active" => true,
],
[
"url" => null,
"label" => "Berikutnya »",
"active" => false,
],
],
"next_page_url" => null,
"path" => "https://invoiceku.id/api/payment-gateway",
"per_page" => 10,
"prev_page_url" => null,
"to" => 2,
"total" => 2,
]
获取产品数据
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Product)->get();
上面的代码中的 get 方法可以接受两个参数,即 integer
类型的 per_page
和 page
,因为端点采用了分页系统,所以您可以轻松地设置每次请求要显示多少数据。以下是如何使用 get 方法的示例:get(per_page:10,page:1)
上述代码的输出将是一个数组,如下所示
[
"current_page" => 1,
"data" => [
[
"name" => "Testing",
"slug" => "testing",
"status" => "published",
"sku" => "3213123",
"plu" => "88999993209",
"price" => 50000,
"description" => "Lorem",
"meta" => null,
"deleted_at" => null,
"created_at" => "2023-02-03T12:50:40.000000Z",
"updated_at" => "2023-02-03T12:50:40.000000Z",
"image_url" => "https://invoiceku.id/storage/1/uTvJpKEkdUFCEEt4DWcn8OeXBHqZLC-metaY29kZS0xLnBuZw==-.png",
"product_id" => "W12N3yGR",
],
[
"name" => "Bala-Bala",
"slug" => "bala-bala",
"status" => "published",
"sku" => "3213123",
"plu" => "88999993209",
"price" => 20000,
"description" => "Bala-bala 12pcs",
"meta" => null,
"deleted_at" => null,
"created_at" => "2023-02-14T15:12:33.000000Z",
"updated_at" => "2023-02-14T15:12:33.000000Z",
"image_url" => "https://is3.cloudhost.id/invoiceku/4/ntO6Nm2n48fXQ8SVvCbgWyEUTC6FaR-metaU2NyZWVuc2hvdCBmcm9tIDIwMjMtMDItMTQgMjAtNTAtMzIucG5n-.png",
"product_id" => "pj4x8mv3",
],
],
"first_page_url" => "https://invoiceku.id/api/product?page=1",
"from" => 1,
"last_page" => 1,
"last_page_url" => "https://invoiceku.id/api/product?page=1",
"links" => [
[
"url" => null,
"label" => "« Sebelumnya",
"active" => false,
],
[
"url" => "https://invoiceku.id/api/product?page=1",
"label" => "1",
"active" => true,
],
[
"url" => null,
"label" => "Berikutnya »",
"active" => false,
],
],
"next_page_url" => null,
"path" => "https://invoiceku.id/api/product",
"per_page" => 10,
"prev_page_url" => null,
"to" => 2,
"total" => 2,
]
创建产品
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\ProductData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Product;
/**
Khusus untuk image, sku, plu, meta anda dapat mengisi atau tidak mengisi field tersebut.
Dan untuk image isi dengan path gambar / url gambar.
**/
$product_data = new ProductData([
"image" => "/images/product-image.png",
"name" => "Bala Bala",
"slug" => "bala-bala",
"status" => "published",
"sku" => "3321442323",
"plu" => "7732198362",
"price" => 10000.0,
"description" => "Bala-bala 12pcs",
"meta" => [
"meta-data" => "meta data value"
],
]);
$product = new Product();
$product->create($product_data);
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil membuat produk",
"data" => [
/**
Data produk yang barusaja dibuat.
**/
],
]
获取产品详细信息
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Product)->detail("product_id");
上述代码的输出将是一个数组,如下
[
"name" => "Bala-Bala",
"slug" => "bala-bala",
"status" => "published",
"sku" => "3213123",
"plu" => "88999993209",
"price" => 20000,
"description" => "Bala-bala 12pcs",
"meta" => null,
"deleted_at" => null,
"created_at" => "2023-02-14T15:12:33.000000Z",
"updated_at" => "2023-02-14T15:12:33.000000Z",
"image_url" => "https://is3.cloudhost.id/invoiceku/4/ntO6Nm2n48fXQ8SVvCbgWyEUTC6FaR-metaU2NyZWVuc2hvdCBmcm9tIDIwMjMtMDItMTQgMjAtNTAtMzIucG5n-.png",
"product_id" => "pj4x8mv3",
]
更改产品数据
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\ProductData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Product;
/**
Khusus untuk image, sku, plu, meta anda dapat mengisi atau tidak mengisi field tersebut.
Dan untuk image isi dengan path gambar / url gambar.
**/
$product_data = new ProductData([
"image" => "/images/product-image.png",
"name" => "Bala Bala",
"slug" => "bala-bala",
"status" => "published",
"sku" => "3321442323",
"plu" => "7732198362",
"price" => 10000.0,
"description" => "Bala-bala 12pcs",
"meta" => [
"meta-data" => "meta data value"
],
]);
$product = new Product();
$product->update("product_id", $product_data);
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil mengubah produk",
"data" => [
/**
Data produk yang barusaja diubah.
**/
],
]
获取客户数据
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Customer)->get();
上面的代码中的 get 方法可以接受两个参数,即 integer
类型的 per_page
和 page
,因为端点采用了分页系统,所以您可以轻松地设置每次请求要显示多少数据。以下是如何使用 get 方法的示例:get(per_page:10,page:1)
上述代码的输出将是一个数组,如下所示
[
"current_page" => 1,
"data" => [
[
"name" => "Example 1",
"email" => "example_1@example.org",
"phone" => "08999389273",
"addresses" => [
[
"city" => "Bandung",
"state" => "Jawa Barat",
"country" => "Indonesia",
"full_address" => "Jl uhuy Ahay",
],
],
"deleted_at" => null,
"created_at" => "2023-02-03T12:51:23.000000Z",
"updated_at" => "2023-02-03T12:51:23.000000Z",
"customer_id" => "W10cNyGR",
],
[
"name" => "Example 2",
"email" => "example_2@example.org",
"phone" => "0877782367235",
"addresses" => [],
"deleted_at" => null,
"created_at" => "2023-02-04T11:06:45.000000Z",
"updated_at" => "2023-02-04T11:06:45.000000Z",
"customer_id" => "yV2v3N4D",
]
],
"first_page_url" => "https://invoiceku.id/api/customer?page=1",
"from" => 1,
"last_page" => 1,
"last_page_url" => "https://invoiceku.id/api/customer?page=1",
"links" => [
[
"url" => null,
"label" => "« Sebelumnya",
"active" => false,
],
[
"url" => "https://invoiceku.id/api/customer?page=1",
"label" => "1",
"active" => true,
],
[
"url" => null,
"label" => "Berikutnya »",
"active" => false,
],
],
"next_page_url" => null,
"path" => "https://invoiceku.id/api/customer",
"per_page" => 10,
"prev_page_url" => null,
"to" => 2,
"total" => 2,
]
创建客户
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\CustomerData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\CustomerAddressData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Customer;
$customer_data = new CustomerData([
"name" => "example customer",
"email" => "example@example.org",
"phone" => "53526176532",
"addresses" => [
new CustomerAddressData([
"full_address" => "jl uhuy ahay",
"city" => "Bandung",
"state" => "Jawa Barat",
"country" => "Indonesia"
])
]
]);
$customer = new Customer;
$customer->create($customer_data);
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil membuat customer",
"data" => [
/**
Data customer yang barusaja dibuat.
**/
],
]
获取客户详细信息
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Customer)->detail("product_id");
上述代码的输出将是一个数组,如下
[
"name" => "example customer",
"email" => "example@example.org",
"phone" => "9911739",
"addresses" => [],
"deleted_at" => null,
"created_at" => "2023-02-12T14:51:00.000000Z",
"updated_at" => "2023-02-12T14:51:00.000000Z",
"customer_id" => "Db1GWrvM",
]
删除客户
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Customer)->delete("customer_id");
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil menghapus customer"
]
更改客户
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\CustomerData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\CustomerAddressData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Customer;
$customer_data = new CustomerData([
"name" => "example customer",
"email" => "example@example.org",
"phone" => "53526176532",
"addresses" => [
new CustomerAddressData([
"full_address" => "jl uhuy ahay",
"city" => "Bandung",
"state" => "Jawa Barat",
"country" => "Indonesia"
])
]
]);
$customer = new Customer;
$customer->update("customer_id", $customer_data);
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil mengubah customer",
"data" => [
/**
Data customer yang barusaja diubah.
**/
],
]
获取发票数据
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Invoice)->get();
上述代码中的 get 方法可以接受三个参数,即 integer
和 string
类型的 per_page
、page
和 order_by
,因为端点采用了分页系统,所以您可以轻松地设置每次请求要显示多少数据。以下是如何使用 get 方法的示例:get(per_page:10, page:1, order_by:"asc")
上述代码的输出将是一个数组,如下所示
[
"current_page" => 1,
"data" => [
[
"invoice_code" => "inv-66732693",
"description" => null,
"status" => "expired",
"note" => null,
"unique_code" => 705,
"amount" => 50000,
"total" => 50705,
"payment_response" => null,
"expired_at" => "2023-02-04T17:00:00.000000Z",
"payment_at" => null,
"deleted_at" => null,
"created_at" => "2023-02-04T09:43:46.000000Z",
"updated_at" => "2023-02-11T08:24:17.000000Z",
"invoice_id" => "l0x2zQGE",
"payment_link" => "https://invoiceku.id/payment/l02zQGE",
"payment_detail" => [
"image_url" => "https://is3.cloudhost.id/invoiceku/payment-gateways/5PyjExBBz64.png",
"account_holder" => "Diki Akbar Asyidiq",
"account_number" => 4020374476,
],
"invoice_items" => [
[
"name" => "Testing",
"description" => "Lorem",
"quantity" => 1,
"price" => 50000,
"image_url" => "https://invoiceku.id/storage/1/uTvJpKEkdUFCEEt4DWcn8OeXBHqZLC-metaY29kZS0xLnBuZw==-.png",
"deleted_at" => null,
"created_at" => "2023-02-04T09:43:46.000000Z",
"updated_at" => "2023-02-04T09:43:46.000000Z",
"invoice_item_id" => "l02xzQGE",
"short_description" => "Lorem",
],
],
"payment_gateway" => [
"name" => "BCA",
"vendor" => "Moota",
"meta" => [
"account_holder" => "Diki Akbar Asyidiq",
"account_number" => 4020374476,
"image_url" => "payment-gateways/5PyjExBBz64.png",
],
"is_active" => 0,
"is_pos" => 0,
"deleted_at" => null,
"created_at" => "2023-02-04T09:43:17.000000Z",
"updated_at" => "2023-02-17T17:15:08.000000Z",
"payment_gateway_id" => "l02dzQGE",
],
"customer" => [
"name" => "Diki Akbar",
"email" => "diki.akbar1304@gmail.com",
"phone" => "0813414833646",
"addresses" => [
[
"city" => "Bandung",
"state" => "Jawa Barat",
"country" => "Indonesia",
"full_address" => "Jl Terusan Cikutra Baru no 3B",
],
],
"deleted_at" => null,
"created_at" => "2023-02-03T12:51:23.000000Z",
"updated_at" => "2023-02-03T12:51:23.000000Z",
"customer_id" => "W12xNyGR",
],
],
[
"invoice_code" => "INV-202302040606457",
"description" => "Pembelian Paket Starter untuk 1 bulan.",
"status" => "expired",
"note" => "Transfer sesuai dengan nominal yang ditentukan hinggal 3 digit terakhir.",
"unique_code" => 328,
"amount" => 50000,
"total" => 50328,
"payment_response" => null,
"expired_at" => "2023-02-05T11:06:45.000000Z",
"payment_at" => null,
"deleted_at" => null,
"created_at" => "2023-02-04T11:06:45.000000Z",
"updated_at" => "2023-02-11T08:24:20.000000Z",
"invoice_id" => "zn4JgfvM",
"payment_link" => "https://invoiceku.id/payment/zn4JgvM",
"payment_detail" => [
"image_url" => "https://is3.cloudhost.id/invoiceku/payment-gateways/5PyjExBBz64.png",
"account_holder" => "Diki Akbar Asyidiq",
"account_number" => 4020374476,
],
"invoice_items" => [
[
"name" => "Starter",
"description" => "Untuk UMKM atau usaha kecil dengan harga yang kecil untuk mendapatkan kualitas yang premium.",
"quantity" => 1,
"price" => 50000,
"image_url" => "https://invoiceku.id/images/colored-logo.jpg",
"deleted_at" => null,
"created_at" => "2023-02-04T11:06:45.000000Z",
"updated_at" => "2023-02-04T11:06:45.000000Z",
"invoice_item_id" => "zn4dJgvM",
"short_description" => "Untuk UMKM atau usaha kecil dengan harga yang keci ...",
],
],
"payment_gateway" => [
"name" => "BCA",
"vendor" => "Moota",
"meta" => [
"account_holder" => "Diki Akbar Asyidiq",
"account_number" => 4020374476,
"image_url" => "payment-gateways/5PyjExBBz64.png",
],
"is_active" => 0,
"is_pos" => 0,
"deleted_at" => null,
"created_at" => "2023-02-04T09:43:17.000000Z",
"updated_at" => "2023-02-17T17:15:08.000000Z",
"payment_gateway_id" => "l021zQGE",
],
"customer" => [
"name" => "Diki Akbar",
"email" => "diki.akbar13042000@gmail.com",
"phone" => "62813431483647",
"addresses" => [],
"deleted_at" => null,
"created_at" => "2023-02-04T11:06:45.000000Z",
"updated_at" => "2023-02-04T11:06:45.000000Z",
"customer_id" => "yVv33N4D",
],
]
],
"first_page_url" => "https://invoiceku.id/api/invoice?page=1",
"from" => 1,
"last_page" => 2,
"last_page_url" => "https://invoiceku.id/api/invoice?page=2",
"links" => [
[
"url" => null,
"label" => "« Sebelumnya",
"active" => false,
],
[
"url" => "https://invoiceku.id/api/invoice?page=1",
"label" => "1",
"active" => true,
],
[
"url" => "https://invoiceku.id/api/invoice?page=2",
"label" => "2",
"active" => false,
],
[
"url" => "https://invoiceku.id/api/invoice?page=2",
"label" => "Berikutnya »",
"active" => false,
],
],
"next_page_url" => "https://invoiceku.id/api/invoice?page=2",
"path" => "https://invoiceku.id/api/invoice",
"per_page" => 10,
"prev_page_url" => null,
"to" => 2,
"total" => 2,
]
创建发票
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\InvoiceData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Data\InvoiceItemData;
use \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Invoice;
$invoice_data = new InvoiceData([
'customer_id' => "W1x2NyGR",
"payment_gateway_id" => "8x23jZ2a",
"invoice_code" => "INV-0009932973",
"expired_at" => "2023-02-03 12:00:00",
"items" => [
new InvoiceItemData([
"name" => "Testing",
"product_id" => "Wx12NyGR",
"quantity" => 1,
"price" => 200000
])
]
]);
$invoice = new Invoice;
$invoice->create($invoice_data)
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil membuat invoice",
"data" => [
/**
Data invoice yang barusaja dibuat.
**/
],
]
获取发票详细信息
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Invocice)->detail("invoice_id");
上述代码的输出将是一个数组,如下
[
"status" => true,
"data" => [
"invoice_code" => "ORDER-20230213224336",
"description" => null,
"status" => "success",
"note" => null,
"unique_code" => 501,
"amount" => 100000,
"total" => 100501,
"payment_response" => null,
"expired_at" => null,
"payment_at" => null,
"deleted_at" => null,
"created_at" => "2023-02-13T15:43:36.000000Z",
"updated_at" => "2023-02-13T16:20:14.000000Z",
"invoice_id" => "z6xG61vp",
"payment_link" => "https://invoiceku.id/payment/z6G61vp",
"payment_detail" => [
"image_url" => "https://is3.cloudhost.id/invoiceku/payment-gateways/5PyjExBBz64.png",
"account_holder" => "Diki Akbar Asyidiq",
"account_number" => 4020374476,
],
],
]
更改发票状态
(new \InvoicekuId\InvoicekuPhpSdk\Domains\Invoice\Objects\Invoice)->updateStatus("invoice_id", "success");
上述代码的返回或输出将符合 API 的输出,如果您成功保存了设置,则状态输出状态将变为 true
,如果未成功则输出相反的 false
。示例输出
[
"status" => true,
"message" => "Berhasil mengubah status Invoice"
]
结论
以上是从配置到 Invoiceku ID 中可用的数据处理教程/使用 SDK 的方法。如果您在使用上述教程时仍有困难,请联系我们邮箱 cs@invoiceku.id
或通过社交媒体私信我们:Instagram Twitter