/** * Create a new PaymentForward. * * OPTIONS: * process_fees_address (string): Address to forward processing fees, if specified. * Allows you to receive a fee for your own services. * process_fees_satoshis (int): Fixed processing fee amount to be sent to the fee address. A fixed satoshi amount or a * percentage is required if a process_fees_address has been * specified. * process_fees_percent (float): Percentage of the transaction to be sent to the fee address. A fixed satoshi amount * or a percentage is required if a process_fees_address has been specified. * callback_url (url): The URL to call anytime a new payment is forwarded. * enable_confirmations (bool): Whether to also call the callback_url with subsequent confirmations of the * forwarding transactions. Automatically sets up a WebHook. * mining_fees_satoshis (int): Mining fee amount to include in the forwarding transaction, in satoshis. If not set, * defaults to 10,000. * transactions array[string]: History of forwarding transaction hashes for this payment forwarding request. * * @param string $destination * @param array $options * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls * @return PaymentForward */ public function createForwardingAddress($destination, $options = array(), $apiContext = null, $restCall = null) { ArgumentValidator::validate($destination, 'destination'); ArgumentArrayValidator::validate($options, 'options'); $paymentForward = new PaymentForward(); $paymentForward->setDestination($destination); // All options correspond to a setter foreach ($options as $option => $optionValue) { if (ModelAccessorValidator::validate($paymentForward, $this->convertToCamelCase($option))) { $setter = "set" . $this->convertToCamelCase($option); $paymentForward->{$setter}($optionValue); } else { throw new \InvalidArgumentException("Invalid option {$option}"); } } return $this->create($paymentForward, $apiContext, $restCall); }
<?php // Run on console: // php -f .\sample\payment-api\CreatePaymentEndpoint.php require __DIR__ . '/../bootstrap.php'; use BlockCypher\Api\PaymentForward; use BlockCypher\Auth\SimpleTokenCredential; use BlockCypher\Client\PaymentForwardClient; use BlockCypher\Rest\ApiContext; $apiContext = ApiContext::create('main', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG')); $paymentForwardClient = new PaymentForwardClient($apiContext); $options = array('callback_url' => 'http://requestb.in/rwp6jirw?uniqid=' . uniqid()); $paymentForward = $paymentForwardClient->createForwardingAddress('15qx9ug952GWGTNn7Uiv6vode4RcGrRemh', $options); // For Sample Purposes Only. $request = new PaymentForward(); $request->setDestination('15qx9ug952GWGTNn7Uiv6vode4RcGrRemh'); $request->setCallbackUrl('http://requestb.in/rwp6jirw?uniqid=' . uniqid()); ResultPrinter::printResult("Create Payment Endpoint", "PaymentForward", $paymentForward->getId(), $request, $paymentForward);