PHP code example of banxa / php-sdk
1. Go to this page and download the library: Download banxa/php-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
banxa / php-sdk example snippets
composer
Banxa::create($subdomain, $apiKey, $apiSecret, $testMode)
$subdomain = 'partner';
$sandboxApiKey = 'xxx-xxx-xxx-xxx-xxx';
$sandboxApiSecret = 'xxxx-xxxx-xxxx-xxxx';
$testMode = true;
Banxa::create($subdomain, $sandboxApiKey, $sandboxApiSecret, $testMode)
$subdomain = 'partner';
$apiKey = 'xxx-xxx-xxx-xxx-xxx';
$apiSecret = 'xxxx-xxxx-xxxx-xxxx';
Banxa::create($subdomain, $apiKey, $apiSecret)
> $banxa->getCountries()
>
[
[
"country_code" => "AD",
"country_name" => "Andora"
],
[
"country_code" => "AE",
"country_name" => "United Arab Emirates"
],
]
> $banxa->getUsStates()
>
[
[
"state_code" => "AL",
"state_name" => "Alabama"
],
[
"state_code" => "AK",
"state_name" => "Alaska"
],
]
> $banxa->getBuyFiatCurrencies()
>
> $banxa->getSellFiatCurrencies()
>
[
[
"fiat_code" => "EUR",
"fiat_name" => "Euro",
"fiat_symbol" => "€",
],
[
"fiat_code" => "GBP",
"fiat_name" => "British Pound Sterling",
"fiat_symbol" => "£",
],
]
> $banxa->getBuyCryptoCurrencies()
>
> $banxa->getSellCryptoCurrencies()
>
[
[
"coin_code"=> "BTC",
"coin_name"=> "Bitcoin",
"blockchains"=> [
[
"code"=> "BTC",
"description"=> "Bitcoin",
"is_default"=> true
]
]
],
[
"coin_code"=> "ETH",
"coin_name"=> "Ethereum",
"blockchains"=> [
[
"code"=> "ETH",
"description"=> "Ethereum (ERC-20)",
"is_default"=> true
],
[
"code"=> "MATIC",
"description"=> "Polygon",
"is_default"=> false
]
]
]
]
> $banxa->getAllPaymentMethods()
>
[
[
"id" => 6036,
"paymentType" => "WORLDPAYCREDIT",
"name" => "Visa/Mastercard",
"description" => "Conveniently buy digital currency using your personal VISA or MasterCard.",
"logo_url" => "https://partner.banxa.com/images/payment-providers/worlpaycredit.png",
"status" => "ACTIVE",
"supported_agents" => [
[
"os" => "ios",
"browser" => "safari"
],
[
"os" => "macos",
"browser" => "safari"
],
[
"os" => "ipados",
"browser" => "safari"
]
],
"type" => "FIAT_TO_CRYPTO",
"supported_fiat" => [
"AED",
],
"transaction_fees" => [
[
"fiat_code" => "AED",
"coin_code" => "BTC",
"fees" => [
[
"name" => "surcharge",
"amount" => 3,
"type" => "fixed"
]
]
],
]
],
[
"id" => 6036,
"paymentType" => "WORLDPAYAPPLE",
"name" => "Apple Pay",
"description" => "Conveniently buy digital currency using your Apple Pay wallet.",
"logo_url" => "https://partner.banxa.com/images/payment-providers/apple-pay.png",
"status" => "ACTIVE",
"supported_agents" => [
[
"os" => "ios",
"browser" => "safari"
],
[
"os" => "macos",
"browser" => "safari"
],
[
"os" => "ipados",
"browser" => "safari"
]
],
"type" => "CRYPTO_TO_FIAT",
"supported_fiat" => [
"AED",
],
"transaction_fees" => [
[
"fiat_code" => "AED",
"coin_code" => "BTC",
"fees" => [
[
"name" => "surcharge",
"amount" => 3,
"type" => "fixed"
]
]
],
]
]
];
> $banxa->getBuyPaymentMethods($fiatCode, $coinCode)
>
[
"id" => 6036,
"paymentType" => "WORLDPAYAPPLE",
"name" => "Apple Pay",
"description" => "Conveniently buy digital currency using your Apple Pay wallet.",
"logo_url" => "https://partner.banxa.com/images/payment-providers/apple-pay.png",
"status" => "ACTIVE",
"supported_agents" => [
[
"os" => "ios",
"browser" => "safari"
],
[
"os" => "macos",
"browser" => "safari"
],
[
"os" => "ipados",
"browser" => "safari"
]
],
"type" => "FIAT_TO_CRYPTO",
"supported_fiat" => [
"AED",
],
"transaction_fees" => [
[
"fiat_code" => "AED",
"coin_code" => "BTC",
"fees" => [
[
"name" => "surcharge",
"amount" => 3,
"type" => "fixed"
]
]
],
]
]
> $banxa->getSellPaymentMethods($coinCode, $fiatCode)
>
[
"id" => 6036,
"paymentType" => "DIRECTCREDIT",
"name" => "Bank Transfer",
"description" => "Sell digital currency to us and have the value directly credited to your bank account",
"logo_url" => "https://partner.banxa.com/images/payment-providers/directcredit.png",
"status" => "ACTIVE",
"supported_agents" => [
[
"os" => "ios",
"browser" => "safari"
],
[
"os" => "macos",
"browser" => "safari"
],
[
"os" => "ipados",
"browser" => "safari"
]
],
"type" => "CRYPTO_TO_FIAT",
"supported_fiat" => [
"AED",
],
"transaction_fees" => [
[
"fiat_code" => "AED",
"coin_code" => "BTC",
"fees" => [
[
"name" => "surcharge",
"amount" => 3,
"type" => "fixed"
]
]
],
]
]
> $banxa->getAllBuyPrices(
> $fiatCode,
> $coinCode,
> $fiatAmount,
> $blockchain
> )
>
[
"spot_price" => "1.07",
"prices" => [
[
"payment_method_id" => 6047,
"type" => "FIAT_TO_CRYPTO",
"spot_price_fee" => "0.00",
"spot_price_including_fee" => "1.07",
"coin_amount" => "93.84000000",
"coin_code" => "USDT",
"fiat_amount" => "100.00",
"fiat_code" => "USD",
"fee_amount" => "0.00",
"network_fee" => "2.37"
],
[
"payment_method_id" => 6058,
"type" => "FIAT_TO_CRYPTO",
"spot_price_fee" => "0.00",
"spot_price_including_fee" => "1.09",
"coin_amount" => "93.84000000",
"coin_code" => "USDT",
"fiat_amount" => "100.00",
"fiat_code" => "USD",
"fee_amount" => "0.00",
"network_fee" => "2.37"
]
]
]
> $banxa->getBuyPrice(
> $fiatCode,
> $coinCode,
> $fiatAmount,
> $paymentMethodId,
> $blockchain
> )
>
[
"payment_method_id" => 6058,
"type" => "FIAT_TO_CRYPTO",
"spot_price_fee" => "0.00",
"spot_price_including_fee" => "1.09",
"coin_amount" => "93.84000000",
"coin_code" => "USDT",
"fiat_amount" => "100.00",
"fiat_code" => "USD",
"fee_amount" => "0.00",
"network_fee" => "2.37"
]
> $banxa->getAllSellPrices(
> $coinCode,
> $fiatCode,
> $coinAmount
> )
>
[
"spot_price" => "1.07",
"prices" => [
[
"payment_method_id" => 6045,
"type" => "CRYPTO_TO_FIAT",
"spot_price_fee" => "0.00",
"spot_price_including_fee" => "32500.00",
"coin_amount" => "0.02000000",
"coin_code" => "BTC",
"fiat_amount" => "100.00",
"fiat_code" => "AUD",
"fee_amount" => "0.00",
"network_fee" => "0.00"
],
[
"payment_method_id" => 6046,
"type" => "CRYPTO_TO_FIAT",
"spot_price_fee" => "0.00",
"spot_price_including_fee" => "32500.00",
"coin_amount" => "0.04000000",
"coin_code" => "BTC",
"fiat_amount" => "650.00",
"fiat_code" => "AUD",
"fee_amount" => "0.00",
"network_fee" => "0.00"
],
]
]
> $banxa->getSellPrice(
> $coinCode,
> $fiatCode,
> $coinAmount,
> $paymentMethodId
> )
>
[
"payment_method_id" => 6033,
"type" => "CRYPTO_TO_FIAT",
"spot_price_fee" => "0.00",
"spot_price_including_fee" => "1.09",
"coin_amount" => "93.84000000",
"coin_code" => "USDT",
"fiat_amount" => "100.00",
"fiat_code" => "USD",
"fee_amount" => "0.00",
"network_fee" => "2.37"
]
> $banxa->getOrders(
> $startDate,
> $endDate,
> $statuses,
> $perPage,
> $page,
> $accountReference
> )
>
[
[
"id" => "e7f3d4e436c8925af84a391f317aaa6e",
"account_id" => "ebfef819583ff4573e6db307abd9c126",
"account_reference" => "banxa-account",
"order_type" => "CRYPTO-BUY",
"ref" => 501903,
"country" => "AU",
"fiat_code" => "AUD",
"fiat_amount" => 100,
"coin_code" => "BTC",
"coin_amount" => 0.00704583,
"wallet_address" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"wallet_address_tag" => null,
"fee" => 0,
"fee_tax" => 0,
"payment_fee" => 2.14,
"payment_fee_tax" => 0.19,
"commission" => 0,
"tx_hash" => "sync-tx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tx_confirms" => 10,
"created_date" => "01-Jul-2022",
"created_at" => "01-Jul-2022 07:51:18",
"payment_type" => "WorldPay Credit Card",
"status" => "complete",
"completed_at" => "01-Jul-2022 07:55:19",
"merchant_fee" => 0,
"merchant_commission" => 0,
"meta_data" => null,
"blockchain" => [
"code" => "BTC",
"description" => "Bitcoin"
]
],
[
"id" => "b719377e3541921297ebef33016fb068",
"account_id" => "ebfef819583ff4573e6db307abd9c126",
"account_reference" => "banxa-account",
"order_type" => "CRYPTO-BUY",
"ref" => 501902,
"country" => "AU",
"fiat_code" => "AUD",
"fiat_amount" => 320,
"coin_code" => "BTC",
"coin_amount" => 0.02255405,
"wallet_address" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"wallet_address_tag" => null,
"fee" => 0,
"fee_tax" => 0,
"payment_fee" => 6.83,
"payment_fee_tax" => 0.62,
"commission" => 0,
"tx_hash" => "sync-tx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tx_confirms" => 10,
"created_date" => "01-Jul-2022",
"created_at" => "01-Jul-2022 07:51:18",
"payment_type" => "WorldPay Credit Card",
"status" => "complete",
"completed_at" => "01-Jul-2022 07:55:19",
"merchant_fee" => 0,
"merchant_commission" => 0,
"meta_data" => null,
"blockchain" => [
"code" => "BTC",
"description" => "Bitcoin"
]
]
]
> $banxa->getOrder($orderId);
>
[
"id" => "b719377e3541921297ebef33016fb068",
"account_id" => "ebfef819583ff4573e6db307abd9c126",
"account_reference" => "banxa-account",
"order_type" => "CRYPTO-BUY",
"ref" => 501902,
"country" => "AU",
"fiat_code" => "AUD",
"fiat_amount" => 320,
"coin_code" => "BTC",
"coin_amount" => 0.02255405,
"wallet_address" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"wallet_address_tag" => null,
"fee" => 0,
"fee_tax" => 0,
"payment_fee" => 6.83,
"payment_fee_tax" => 0.62,
"commission" => 0,
"tx_hash" => "sync-tx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"tx_confirms" => 10,
"created_date" => "01-Jul-2022",
"created_at" => "01-Jul-2022 07:51:18",
"payment_type" => "WorldPay Credit Card",
"status" => "complete",
"completed_at" => "01-Jul-2022 07:55:19",
"merchant_fee" => 0,
"merchant_commission" => 0,
"meta_data" => null,
"blockchain" => [
"code" => "BTC",
"description" => "Bitcoin"
]
]
> $banxa->createBuyOrder(
> $buyOrderTransaction,
> $returnUrlOnSuccess,
> $returnUrlOnFailure,
> $returnUrlOnCancelled,
> $metadata,
> $readOnlyAmounts,
> $iframeRefererDomain,
> $optionalOrderParameters
> );
>
> $buyOrderTransaction = BuyOrderTransaction::createFromFiatAmount(
> $accountReference,
> $fiatCode,
> $coinCode,
> $fiatAmount,
> $walletAddress,
> $paymentMethodId
> );
>
> $buyOrderTransaction = BuyOrderTransaction::createFromCoinAmount(
> $accountReference,
> $fiatCode,
> $coinCode,
> $coinAmount,
> $walletAddress,
> $paymentMethodId
> );
>
> $buyOrderTransaction = BuyOrderTransaction::createDynamic(
> $accountReference,
> $source,
> $target,
> $sourceAmount,
> $targetAmount,
> $walletAddress,
> $refundAddress,
> $paymentMethodId,
> $blockchain,
> $walletAddressTag
> );
>
> $optionalOrderParameters = optionalOrderParameters::create(
> $sourceAddress,
> $sourceAddressTag,
> $email,
> $mobile,
> );
>
>$buyOrderTransaction = BuyOrderTransaction::createFromFiatAmount($accountReference, $fiatCode, $coinCode, $fiatAmount, $walletAddress, $paymentMethodId, $blockchain, $walletAddressTag);// From Fiat Amount
>
>$buyOrderTransaction = BuyOrderTransaction::createFromCoinAmount($accountReference, $fiatCode, $coinCode, $coinAmount, $walletAddress, $paymentMethodId, $blockchain, $walletAddressTag);// From Coin Amount
>
>$buyOrderTransaction = BuyOrderTransaction::createDynamic($accountReference, $source, $target, $sourceAmount, null, $walletAddress, null, $paymentMethodId, $blockchain, $walletAddressTag); // Dynamic
>
>$buyOrderTransaction = BuyOrderTransaction::createDynamic($accountReference, $source, $target, null, $targetAmount, $walletAddress, null, $paymentMethodId, $blockchain, $walletAddressTag); // Dynamic
>
>$optionalOrderParameters = OptionalOrderParameters::create($sourceAddress, $sourceAddressTag, $email, $mobile);
>
> $banxa->createBuyOrder(
> $buyOrderTransaction,
> $returnUrlOnSuccess,
> $returnUrlOnFailure,
> $returnUrlOnCancelled,
> $metadata,
> $readOnlyAmounts,
> $iframeRefererDomain,
> $optionalOrderParameters
> );
>
>[
> "id" => "b890df4aee4583a25ca8da17eb863c81",
> "account_id" => "3ec8d3c67617af11d84a18931c4e369d",
> "account_reference" => "banxa-test-01",
> "order_type" => "CRYPTO-BUY",
> "fiat_code" => "AUD",
> "fiat_amount" => 1,
> "coin_code" => "BTC",
> "wallet_address" => "1LbQ1WNTsm1Nzj1hbh3WDCbEim1oUg5rfi",
> "blockchain" => [
> "id" => 1,
> "code" => "BTC",
> "description" => "Bitcoin"
> ],
> "created_at" => "17-Aug-2022 00:09:03",
> "checkout_url" => "https://your-return-url"
>]
>
> $banxa->createNftBuyOrder(
> $nftBuyOrderTransaction,
> $nftData,
> $returnUrlOnSuccess,
> $returnUrlOnFailure,
> $returnUrlOnCancelled,
> $iframeRefererDomain
> );
>
> $nftBuyOrderTransaction = NftBuyOrderTransaction::create(
> $accountReference,
> $fiatCode,
> $coinCode,
> $fiatAmount,
> $walletAddress,
> $paymentMethodId = null,
> $blockchain = null,
> $walletAddressTag = null
> );
>
> $nftData = NftData::create(
> $purchaseReference,
> $nft,
> $metaData
> );
>
> $nft = Nft::create(
> $name,
> $collection,
> $nftMedia,
> );
>
> $nftMedia = VideoNftMedia::create($link);
>
> $nftMedia = ImageNftMedia::create($link);
>
>
> $nftBuyOrderTransaction = NftBuyOrderTransaction::create(
> $accountReference,
> $fiatCode,
> $coinCode,
> $fiatAmount,
> $walletAddress,
> $paymentMethodId,
> $blockchain,
> $walletAddressTag
> );
>
>
> $nftMedia = ImageNftMedia::create($link); // OR $nftMedia = VideoNftMedia::create($link)
>
>
> $nft = Nft::create(
> $name,
> $collection,
> $nftMedia,
> );
>
> $nftData = NftData::create(
> $purchaseReference,
> $nft,
> $metaData
> );
>
> $banxa->createNftBuyOrder(
> $nftBuyOrderTransaction,
> $nftData,
> $returnUrlOnSuccess,
> $returnUrlOnFailure,
> $returnUrlOnCancelled,
> $iframeRefererDomain,
> );
>
>[
> "id" => "b890df4aee4583a25ca8da17eb863c81",
> "account_id" => "3ec8d3c67617af11d84a18931c4e369d",
> "account_reference" => "Banxa-Testing-01",
> "order_type" => "NFT-BUY",
> "blockchain" => [
> "id" => 1,
> "code" => "ETH",
> "description" => "Ethereum (ERC-20)"
> ],
> "created_at" => "17-Aug-2022 00:09:03",
> "checkout_url" => "https://your-return-url"
>]
>
> $banxa->createSellOrder(
> $sellOrderTransaction,
> $returnUrlOnSuccess,
> $returnUrlOnFailure,
> $returnUrlOnCancelled,
> $metadata,
> $readOnlyAmounts,
> $iframeRefererDomain,
> $optionalOrderParameters,
> )
>
> $sellOrderTransaction = SellOrderTransaction::createFromFiatAmount(
> $accountReference,
> $fiatCode,
> $coinCode,
> $fiatAmount,
> $refundAddress,
> $paymentMethodId,
> $blockchain,
> $walletAddressTag,
> );
>
> $sellOrderTransaction = SellOrderTransaction::createFromCoinAmount(
> $accountReference,
> $fiatCode,
> $coinCode,
> $coinAmount,
> $refundAddress,
> $paymentMethodId,
> $blockchain,
> $walletAddressTag,
> );
>
> $sellOrderTransaction = SellOrderTransaction::createDynamic(
> $accountReference,
> $source,
> $target,
> $sourceAmount,
> $targetAmount,
> $walletAddress,
> $refundAddress,
> $paymentMethodId,
> $blockchain,
> $walletAddressTag
> );
>
> $optionalOrderParameters = optionalOrderParameters::create(
> $sourceAddress,
> $sourceAddressTag,
> $email,
> $mobile,
> );
>
>$sellOrderTransaction = SellOrderTransaction::createFromFiatAmount($accountReference, $fiatCode, $coinCode, $fiatAmount, $refundAddress, $paymentMethodId, $blockchain, $walletAddressTag);// From Fiat Amount
>
>$sellOrderTransaction = SellOrderTransaction::createFromCoinAmount($accountReference, $fiatCode, $coinCode, $coinAmount, $refundAddress, $paymentMethodId, $blockchain, $walletAddressTag);// From Coin Amount
>
>$sellOrderTransaction = SellOrderTransaction::createDynamic($accountReference, $source, $target, $sourceAmount, null, null, $refundAddress, $paymentMethodId, $blockchain, $walletAddressTag); // Dynamic
>
>$sellOrderTransaction = SellOrderTransaction::createDynamic($accountReference, $source, $target, null, $targetAmount, null, $refundAddress, $paymentMethodId, $blockchain, $walletAddressTag); // Dynamic
>
>$optionalOrderParameters = OptionalOrderParameters::create($sourceAddress, $sourceAddressTag, $email, $mobile);
>
> $banxa->createSellOrder(
> $sellOrderTransaction,
> $returnUrlOnSuccess,
> $returnUrlOnFailure,
> $returnUrlOnCancelled,
> $metadata,
> $readOnlyAmounts,
> $iframeRefererDomain,
> $optionalOrderParameters,
> );
>
>[
> "id" => "b890df4aee4583a25ca8da17eb863c81",
> "account_id" => "3ec8d3c67617af11d84a18931c4e369d",
> "account_reference" => "banxa-test-01",
> "order_type" => "CRYPTO-SELL",
> "fiat_code" => "AUD",
> "fiat_amount" => 1,
> "coin_code" => "BTC",
> "wallet_address" => "1LbQ1WNTsm1Nzj1hbh3WDCbEim1oUg5rfi",
> "blockchain" => [
> "id" => 1,
> "code" => "BTC",
> "description" => "Bitcoin"
> ],
> "created_at" => "17-Aug-2022 00:09:03",
> "checkout_url" => "https://your-return-url"
>
>]
>
> $banxa->confirmSellOrder(
> $orderId,
> $txHash,
> $sourceAddress,
> $destinationAddress,
> $sourceAddressTag,
> $destinationAddressTag
> )
>
[
"id" => "ee94a43403fb608f341dd5c4c899b846",
"account_id" => "d6e7ab2b8f638bed61dc0ac5bec37d4d",
"account_reference" => "banxa-account",
"order_type" => "CRYPTO-SELL",
"payment_type" => "CLEARJCNSELLFP",
"ref" => 507000,
"fiat_code" => "AUD",
"fiat_amount" => 100,
"coin_code" => "BTC",
"coin_amount" => 0.00286436,
"wallet_address" => null,
"wallet_address_tag" => null,
"fee" => 9.1,
"fee_tax" => 0,
"payment_fee" => 0,
"payment_fee_tax" => 0,
"commission" => 0.1,
"tx_hash" => null,
"tx_confirms" => 0,
"created_date" => "01-Jul-2022",
"created_at" => "01-Jul-2022 07:51:18",
"status" => "in progress",
"completed_at" => null,
"merchant_fee" => 6.54,
"merchant_commission" => 0.05,
"meta_data" => null,
"blockchain" => [
"id" => 1,
"code" => "BTC",
"description" => "Bitcoin"
]
]
> $banxa->createIdentity(
> $identitySharingCollection,
> $customerDetails,
> $residentialAddress
> $customerIdentity,
> $identityDocumentCollection,
> )
>
IdentitySharingCollection::create($kycProviders)
IdentitySharingProvider::create($provider, $token)
$customerDetail = CustomerDetail::create($accountReference, $mobileNumber, $emailAddress);
$residentialAddress = ResidentialAddress::create($country, $addressLine, $suburb, $postCode, $state);
$customerIdentity = CustomerIdentity::create($givenName, $surname, $dateOfBirth);
IdentityDocument::create($documentType, $imageLinks, $documentNumber)
$kycProviders = [
IdentitySharingProvider::create($provider, $token),
IdentitySharingProvider::create($provider, $token),
];
$documents = [
IdentityDocument::create($documentType, $imageLinks, $documentNumber),
IdentityDocument::create($documentType, $imageLinks),
];
$identitySharingCollection = IdentitySharingCollection::create($kycProviders);
$customerDetail = CustomerDetail::create($accountReference, $mobileNumber, $emailAddress);
$residentialAddress = ResidentialAddress::create($country, $addressLine, $suburb, $postCode, $state);
$customerIdentity = CustomerIdentity::create($givenName, $surname, $dateOfBirth);
$identityDocumentCollection = IdentityDocumentCollection::create($documents);
$banxa->createIdentity(
$identitySharingCollection,
$customerDetail,
$residentialAddress,
$customerIdentity,
$identityDocumentCollection
);
[
"account_id" => "28d517af407a0566204acd75e3a8e5b7",
"account_reference" => "test001001"
]