include __DIR__ . '/../../vendor/autoload.php'; use alxmsl\Cli\CommandPosix; use alxmsl\Cli\Exception\RequiredOptionException; use alxmsl\Cli\Option; use alxmsl\PaymentNinja\Client; $publicKey = ''; $privateKey = ''; $payerResponse = ''; $merchantData = ''; $Command = new CommandPosix(); $Command->appendHelpParameter('show help'); $Command->appendParameter(new Option('data', 'd', 'ACS merchant data', Option::TYPE_STRING, true), function ($name, $value) use(&$merchantData) { $merchantData = (string) $value; }); $Command->appendParameter(new Option('private', 'r', 'project private key', Option::TYPE_STRING, true), function ($name, $value) use(&$privateKey) { $privateKey = (string) $value; }); $Command->appendParameter(new Option('public', 'b', 'project public key', Option::TYPE_STRING, true), function ($name, $value) use(&$publicKey) { $publicKey = (string) $value; }); $Command->appendParameter(new Option('response', 'e', 'ACS payer response', Option::TYPE_STRING, true), function ($name, $value) use(&$payerResponse) { $payerResponse = (string) $value; }); try { $Command->parse(true); $Client = new Client($publicKey, $privateKey); $Response = $Client->cardAuthenticate($payerResponse, $merchantData)->execute(); printf("%s\n", $Response); } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }
$number = ''; $securityCode = ''; $callback = null; $Command = new CommandPosix(); $Command->appendHelpParameter('show help'); $Command->appendParameter(new Option('callback', 'c', 'callback JSONP function name', Option::TYPE_STRING), function ($name, $value) use(&$callback) { $callback = (string) $value; }); $Command->appendParameter(new Option('month', 'm', 'expiration month', Option::TYPE_STRING, true), function ($name, $value) use(&$expirationMonth) { $expirationMonth = (int) $value; }); $Command->appendParameter(new Option('number', 'n', 'card number', Option::TYPE_STRING, true), function ($name, $value) use(&$number) { $number = (string) $value; }); $Command->appendParameter(new Option('public', 'b', 'project public key', Option::TYPE_STRING, true), function ($name, $value) use(&$publicKey) { $publicKey = (string) $value; }); $Command->appendParameter(new Option('security', 's', 'card security code', Option::TYPE_STRING, true), function ($name, $value) use(&$securityCode) { $securityCode = (string) $value; }); $Command->appendParameter(new Option('year', 'y', 'expiration year', Option::TYPE_STRING, true), function ($name, $value) use(&$expirationYear) { $expirationYear = (int) $value; }); try { $Command->parse(true); $Client = new Client($publicKey); $Response = $Client->cardGetToken($number, $expirationMonth, $expirationYear, $securityCode, $callback)->execute(); printf("%s\n", $Response); } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }
}); $Command->appendParameter(new Option('remember', 'm', 'indicates whether a user wants to remember his credit card in Merchant\'s service. If true, then permanentToken in response will contain token, that will be used for transaction processing, instead of temporary token', Option::TYPE_BOOLEAN), function ($name, $value) use(&$remember) { $remember = (bool) $value; }); $Command->appendParameter(new Option('token', 't', 'credit card token (temporary or permanent)', Option::TYPE_STRING, true), function ($name, $value) use(&$cardToken) { $cardToken = (string) $value; }); $Command->appendParameter(new Option('trial', 'f', 'Recurring trial period in days (first recurring payment will occur after trial). Recurring trial will work only if recurring interval is set', Option::TYPE_STRING), function ($name, $value) use(&$recurringTrial) { $recurringTrial = (int) $value; }); $Command->appendParameter(new Option('url', 'l', 'URL where 3DSecure service will return user after the authentication', Option::TYPE_STRING, true), function ($name, $value) use(&$url) { $url = (string) $value; }); $Command->appendParameter(new Option('user', 'u', 'user identifier', Option::TYPE_STRING, true), function ($name, $value) use(&$user) { $user = (string) $value; }); $Command->appendParameter(new Option('verify', 'v', 'if set to 1, then transaction price will be set to 1 EUR, that will be put on hold and then instantly returned', Option::TYPE_BOOLEAN), function ($name, $value) use(&$verifyCard) { $verifyCard = (bool) $value; }); try { $Command->parse(true); $Client = new Client($publicKey, $privateKey); $Response = $Client->cardProcess($user, $cardToken, $orderId, $price, $currency, $description, $ip, $url, $remember, $verifyCard, $recurring, $recurringInterval, $recurringTrial, $attributes)->execute(); printf("%s\n", $Response); } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }
$displayName = (string) $value; }); $Command->appendParameter(new Option('email', 'e', 'user email address', Option::TYPE_STRING, true), function ($name, $value) use(&$email) { $email = (string) $value; }); $Command->appendParameter(new Option('ip', 'i', 'user ip address', Option::TYPE_STRING, true), function ($name, $value) use(&$ip) { $ip = (string) $value; }); $Command->appendParameter(new Option('locale', 'l', 'user\'s locale (ISO 639-1)', Option::TYPE_STRING), function ($name, $value) use(&$locale) { $locale = (string) $value; }); $Command->appendParameter(new Option('phone', 'p', 'user\'s phone number', Option::TYPE_STRING), function ($name, $value) use(&$phone) { $phone = (string) $value; }); $Command->appendParameter(new Option('private', 'r', 'project private key', Option::TYPE_STRING, true), function ($name, $value) use(&$privateKey) { $privateKey = (string) $value; }); $Command->appendParameter(new Option('public', 'b', 'project public key', Option::TYPE_STRING, true), function ($name, $value) use(&$publicKey) { $publicKey = (string) $value; }); $Command->appendParameter(new Option('user', 'u', 'user unique unchangeable identifier', Option::TYPE_STRING, true), function ($name, $value) use(&$user) { $user = (string) $value; }); try { $Command->parse(true); $Client = new Client($publicKey, $privateKey); $Response = $Client->userResolve($user, $email, $ip, $displayName, $locale, $phone)->execute(); printf("%s\n", $Response); } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }
}); $Command->appendParameter(new Option('description', 'd', 'product description', Option::TYPE_STRING), function ($name, $value) use(&$description) { $description = (string) $value; }); $Command->appendParameter(new Option('order', 'o', 'merchant\'s order ID that will be returned back in a callback', Option::TYPE_STRING), function ($name, $value) use(&$orderId) { $orderId = (int) $value; }); $Command->appendParameter(new Option('price', 'p', 'price in real currency', Option::TYPE_STRING, true), function ($name, $value) use(&$price) { $price = (double) $value; }); $Command->appendParameter(new Option('private', 'r', 'project private key', Option::TYPE_STRING, true), function ($name, $value) use(&$privateKey) { $privateKey = (string) $value; }); $Command->appendParameter(new Option('public', 'b', 'project public key', Option::TYPE_STRING, true), function ($name, $value) use(&$publicKey) { $publicKey = (string) $value; }); $Command->appendParameter(new Option('user', 'u', 'user identifier', Option::TYPE_STRING, true), function ($name, $value) use(&$user) { $user = (string) $value; }); $Command->appendParameter(new Option('verify', 'v', 'if set to 1, then transaction price will be set to 1 EUR, that will be put on hold and then instantly returned', Option::TYPE_BOOLEAN), function ($name, $value) use(&$verifyCard) { $verifyCard = (bool) $value; }); try { $Command->parse(true); $Client = new Client($publicKey, $privateKey); $Response = $Client->cardProcessRecurring($user, $price, $currency, $orderId, $description)->execute(); printf("%s\n", $Response); } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }
* * Cancel user's recurring script * @author alxmsl */ include __DIR__ . '/../../vendor/autoload.php'; use alxmsl\Cli\CommandPosix; use alxmsl\Cli\Exception\RequiredOptionException; use alxmsl\Cli\Option; use alxmsl\PaymentNinja\Client; $publicKey = ''; $privateKey = ''; $user = ''; $Command = new CommandPosix(); $Command->appendHelpParameter('show help'); $Command->appendParameter(new Option('private', 'r', 'project private key', Option::TYPE_STRING, true), function ($name, $value) use(&$privateKey) { $privateKey = (string) $value; }); $Command->appendParameter(new Option('public', 'b', 'project public key', Option::TYPE_STRING, true), function ($name, $value) use(&$publicKey) { $publicKey = (string) $value; }); $Command->appendParameter(new Option('user', 'u', 'user identifier', Option::TYPE_STRING, true), function ($name, $value) use(&$user) { $user = (string) $value; }); try { $Command->parse(true); $Client = new Client($publicKey, $privateKey); $Response = $Client->userCancelRecurring($user)->execute(); printf("%s\n", $Response); } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }
public function testCardProcessRecurring() { $Client = new Client(111, 222); $Request = $Client->cardProcessRecurring('999', 5.4, 'EUR'); $this->assertEquals(['project' => '111', 'user' => '999', 'price' => 5.4, 'currency' => 'EUR', 'signature' => '7cefe246acf59297fd3673a06d890acdeb6c7e27848e1531328b3060250e466b'], $this->getRequestParametersProperty($Request)); $Request = $Client->cardProcessRecurring('999', 5.4, 'EUR', '777'); $this->assertEquals(['project' => '111', 'user' => '999', 'price' => 5.4, 'currency' => 'EUR', 'order_id' => '777', 'signature' => 'c19bdae6d3041ca4b3f462a1338a5e3c46455152b4a218272b7c3cc2f077767e'], $this->getRequestParametersProperty($Request)); $Request = $Client->cardProcessRecurring('999', 5.4, 'EUR', '777', 'Lorem recurring'); $this->assertEquals(['project' => '111', 'user' => '999', 'price' => 5.4, 'currency' => 'EUR', 'order_id' => '777', 'description' => 'Lorem recurring', 'signature' => 'ebeb906d67d3031f3a81eecf0d655b2b822be7c2dee07aea2eeb94a0d512f44d'], $this->getRequestParametersProperty($Request)); }
public function testRequestTimeout() { $timeout = 60; $Client = new Client('pub_key', 'private_key'); $Client->setTimeout($timeout); $Class = new ReflectionClass(Client::class); $PropertyParameters = $Class->getProperty('timeout'); $PropertyParameters->setAccessible(true); $this->assertEquals($timeout, $PropertyParameters->getValue($Client)); }
$privateKey = ''; $publicKey = ''; $user = ''; $Command = new CommandPosix(); $Command->appendHelpParameter('show help'); $Command->appendParameter(new Option('currency', 'c', 'recurring currency code (ISO 4217)', Option::TYPE_STRING), function ($name, $value) use(&$currency) { $currency = (string) $value; }); $Command->appendParameter(new Option('interval', 'i', 'automatic recurring interval in days (if set 0, then only manual recurring will remain active)', Option::TYPE_STRING), function ($name, $value) use(&$interval) { $interval = (int) $value; }); $Command->appendParameter(new Option('price', 'p', 'recurring payment price', Option::TYPE_STRING), function ($name, $value) use(&$price) { $price = (double) $value; }); $Command->appendParameter(new Option('private', 'r', 'project private key', Option::TYPE_STRING, true), function ($name, $value) use(&$privateKey) { $privateKey = (string) $value; }); $Command->appendParameter(new Option('public', 'b', 'project public key', Option::TYPE_STRING, true), function ($name, $value) use(&$publicKey) { $publicKey = (string) $value; }); $Command->appendParameter(new Option('user', 'u', 'user identifier', Option::TYPE_STRING, true), function ($name, $value) use(&$user) { $user = (string) $value; }); try { $Command->parse(true); $Client = new Client($publicKey, $privateKey); $Response = $Client->userChangeRecurring($user, $interval, $price, $currency)->execute(); printf("%s\n", $Response); } catch (RequiredOptionException $Ex) { $Command->displayHelp(); }