{"id":18235698,"url":"https://github.com/Ekliptor/cashp","last_synced_at":"2025-04-04T04:30:23.832Z","repository":{"id":34985251,"uuid":"193613287","full_name":"Ekliptor/cashp","owner":"Ekliptor","description":"PHP library for Bitcoin Cash (BCH) and SLP token payments","archived":false,"fork":false,"pushed_at":"2023-01-07T11:57:32.000Z","size":217,"stargazers_count":11,"open_issues_count":7,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T19:51:30.099Z","etag":null,"topics":["bitcoin","bitcoin-cash","cryptocurrency","ecommerce","laravel","php","php-library","php7","wordpress"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ekliptor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-25T01:48:18.000Z","updated_at":"2024-10-16T12:36:52.000Z","dependencies_parsed_at":"2023-01-15T11:30:17.134Z","dependency_job_id":null,"html_url":"https://github.com/Ekliptor/cashp","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ekliptor%2Fcashp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ekliptor%2Fcashp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ekliptor%2Fcashp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ekliptor%2Fcashp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ekliptor","download_url":"https://codeload.github.com/Ekliptor/cashp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247123058,"owners_count":20887258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","bitcoin-cash","cryptocurrency","ecommerce","laravel","php","php-library","php7","wordpress"],"created_at":"2024-11-05T00:02:44.327Z","updated_at":"2025-04-04T04:30:23.488Z","avatar_url":"https://github.com/Ekliptor.png","language":"PHP","funding_links":[],"categories":["Libraries \u0026 SDKs"],"sub_categories":["PHP"],"readme":"# CashP - PHP library for Bitcoin Cash (BCH) and SLP token payments\nThis is a PHP library to enable [BitCoin Cash (BCH)](https://www.bitcoincash.org/) and [SLP token](https://simpleledger.cash/) payments.\nYou can easily use this with WordPress, Laravel and other PHP frameworks.\n\n#### Installation\nWith composer (recommended):\n```\ncomposer require \"ekliptor/cashp\"\n```\n\nManual installation:\n\n1. Download the source code and include `cashp.php` from the root directory of this library.\n2. Download the source of this [PHP QR-code package](https://github.com/Ekliptor/qr-code) and extract it to `src/phpqrcode`\n\n#### Requirements\n```\nPHP \u003e= 7.1\n```\n\n## Features\n* on-chain payments without going through a 3rd party\n* configurable open-source API backends such as: [rest.bitcoin.com](https://github.com/Bitcoin-com/rest.bitcoin.com) or [BCHD](https://github.com/gcash/bchd)\n* 1-time address generation for payments using xPub (so your wallet's private key is not stored on the server)\n* generate QR codes with BCH and SLP payment URIs\n\n## Docs\nTake a look at [code examples](https://github.com/Ekliptor/cashp/tree/master/examples).\n\n#### CashP class\n##### __construct(CashpOptions $options = null)\nCreate the main API class.\n* `CashpOptions $options` - (optional) API options (see below)\n\n##### getRate(): ExchangeRate \nReturn the exchange rate API.\n\n##### getBlockchain(): AbstractBlockchainApi\nReturn the Blockchain API to generate addresses, check balances, transactions,...\n\n##### generateQrCodeForAddress(string $fileLocal, string $address, float $amountBCH, float $amountToken = 0.0, string $tokenID = \"\"): bool\nGenerate a QR code for a payment.\n* `string $fileLocal` - A path on your local filesystem to store the QR code file. This should be accessible from the web if you want to display the QR code to users.\nIf the given file already exists it will NOT be overwritten (QR codes are meant to be generated \u0026 cached in your web temp directory).\n* `string $address` - The (1-time) BCH (or SLP) address created for this payment.\n* `float $amountBCH` - The amount in BCH. Can be 0 if the user pays the full amount in SLP tokens. \n* `float $amountToken` - (optional) The amount of the optional token to be received.\n* `string $tokenID` - (optional) The hex ID of the SLP token. Required if $amountToken \u003e 0.\n\nreturns `bool` - true on success, false otherwise\n\n---\n\n##### createPaymentURI(string $address, float $amountBCH, float $amountToken = 0.0, string $tokenID = \"\"): string\nReturn a payment URI (starting with \"bitcoincash:\" or \"simpleledger:\" if $amountToken \u003e 0) for the given $address.\n* `string $address` - The receiving BCH (or SLP) address.\n* `float $amountBCH` - The amount in BCH to receive.\n* `float $amountToken` - (optional) The amount of SLP tokens to receive.\n* `string $tokenID` - (optional) The hex ID of the SLP token. Required if $amountToken \u003e 0.\n\nreturns `string`\n\n---\n\n##### getBadgerButton(array $btnConf, string $address, float $amountBCH, float $amountToken = 0.0, string $tokenID = \"\"): string\nGet the HTML code of a BadgerButton. See https://badger.bitcoin.com/\n* `array $btnConf` - associative array with buttom config\n    * text (string) The text of the button\n    * callback (string, optional) The name of a callback function present on the global window to be called after payment. Parameters: string chainTxID\n    * cssClass (string, optional) Additional CSS classes for the button.\n    * forceIndludeJs (bool, optional) default false - Include the JavaScript library again. Only use this if you are generating HTML for multiple pages.\n* `string $address` - The receiving BCH (or SLP) address.\n* `float $amountBCH` - The amount in BCH to receive.\n* `float $amountToken` - (optional) The amount of SLP tokens to receive.\n* `string $tokenID` - (optional) The hex ID of the SLP token. Required if $amountToken \u003e 0.\n\nreturns `string` - The button HTML.\n\n---\n\n##### isValidBchAddress(string $bchAddress): bool\nCheck if a BCH address is valid.\n* `string $bchAddress` - The address in CashAddress format starting with 'bitcoincash:'\n\nreturns `bool` - True if the address is valid, false otherwise.\n\n---\n\n##### isValidSlpAddress(string $slpAddress): bool\nCheck if a SLP address is valid.\n* `string $slpAddress` - The address starting with 'simpleledger:'\n\nreturns `bool` - True if the address is valid, false otherwise.\n\n---\n\n##### getReturnAddress(Transaction $tx): string\nGets the return BCH address (belonging to the sender senders address) defined\nas the last address in transaction outputs.\n* `Transaction $tx` - The transaction from getTransaction() call.\n\nreturns `string` - the address\n\n---\n\n##### getReturnSlpAddress(Transaction $tx): string\nGets the return SLP address (belonging to the sender senders address) defined\nas the last address in transaction outputs.\n* `Transaction $tx` - The transaction from getTransaction() call.\n\nreturns `string` - the address\n\n---\n\n\n#### CashpOptions class\nA set of advanced config properties.\n* `$httpAgent = null` - The HTTP implementation used to make HTTP requests.\nValues: BasicHttpAgent|CurlHttpAgent|WordpressHttpAgent\nDefaults to BasicHttpAgent, but you should use a better one according to your PHP setup.\n* `$exchangeRateExpirationMin = 60` - How long the crawled exchange rate shall stay in cache. Currently rates are not saved beyond script execution.\n* `$httpTimeoutSec = 10` - The timeout for HTTP requests to the REST API backend.\n* `$blockchainApiImplementation = \"BitcoinComRestApi\"` - The REST API backend implementation to use. Allowed values: BitcoinComRestApi|BchdProtoGatewayApi|SlpDbApi\n\n\n#### ExchangeRate class\nAn API to get BCH exchanges rates to fiat currencies.\n\n##### getRate(string $currency = \"USD\"): float\nGet the current exchange rate for BCH.\n* `string $currency` - A fiat currency such as USD|EUR|JPY\n\nreturns `float`\n\n---\n\n\n#### BlockchainApi class\nThe Blockchain API to generate addresses, check balances, transactions,...\n\n##### static setLogger(callable $loggerFn): void\nSet a logger function for errors and debug output. Use this to write to a logfile or database.\nIf no function is provided everything will be printed using 'echo'.\n* `callable $loggerFn(string $subject, mixed $error, mixed $data = null)` - parameters of the PHP callable\n\n##### setHttpAgent(AbstractHttpAgent $agent): void\nSet a a HTTP implementation for requests (cURL, Wordpress HTTP API,...)\n* `AbstractHttpAgent $agent` - \n\n##### getConfirmationCount(string $transactionID): int\nReturn the number of confirmation for the given blockchain transaction ID.\n* `string $transactionID` - \n\nreturns `int` - The number of confirmations or -1 if the $transactionID doesn't exist.\n\n---\n\n##### createNewAddress(string $xPub, int $addressCount, string $hdPathFormat = '0/%d'): ?BchAddress\nCreates a new address from the xPub.\n* `string $xPub` - The extended public key. Called 'Master Public Key' in Electron Cash.\n* `int $addressCount` - The number of the next address to generate a unique address. Usually this should be an incrementing integer.\n* `string $hdPathFormat` - (optional) The HD path to be used for creating address children.\n\nreturns `BchAddress` - the address or `null` on failure\n\n---\n\n##### getTokenInfo(string $tokenID): ?SlpToken\nGet general (network-wide) info about a SLP token.\n* `string $tokenID` - \n\nreturns `SlpToken` - The token or `null` on failure\n\n---\n\n##### getAddressBalance(string $address): float\nReturn the BCH balance of the given address (including unconfirmed transactions).\n* `string $address` - The BCH address in CashAddress format.\n\nreturns `float` - The balance or -1 if the address doesn't exist.\n\n---\n\n##### getAddressTokenBalance(string $address, string $tokenID): float\nReturn the token balance of the given SLP address (including unconfirmed transactions).\n* `string $address` - \n* `string $tokenID` - \n\nreturns `float` - The balance or -1 if the address doesn't exist.\n\n---\n\n##### getAddressDetails(string $address): ?BchAddress\nReturn the BCH Address with all its properties such as balance, TXIDs,...\n* `string $address` - The BCH address in CashAddress format.\n\nreturns `BchAddress` - the address or `null` on failure\n\n---\n\n##### getSlpAddressDetails(string $address, string $tokenID): ?SlpTokenAddress\nReturn the SLP token details of a given address include balance, TXIDs,...\n* `string $address` - \n* `string $tokenID` - \n\nreturns `SlpTokenAddress` - The token or `null` on failure\n\n---\n\n##### getTransaction(string $transactionID): ?Transaction\nReturns a transaction with all inputs and outputs including SLP data.\n* `string $transactionID` -\n\nreturns `Transaction` - The transaction or `null` on failure\n\n---\n\n\n## Testing\nTo run unit tests type the following command in the project root directory (requires PHPUnit, installed automatically with Composer):\n\n`./vendor/bin/phpunit --bootstrap vendor/autoload.php tests`\n\n\n## ToDo\n* add SLP address verification\n* implement more functions of the REST API\n* implement address creation using xPub with SLPDB (after it's supported)\n\n\n## Contact\n[Twitter](https://twitter.com/ekliptor)\n\n[WordPress plugin](https://cashtippr.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEkliptor%2Fcashp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEkliptor%2Fcashp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEkliptor%2Fcashp/lists"}