GenesisGateway / genesis_php

Genesis PHP client integration
MIT License
7 stars 6 forks source link

How to deposit 0.01 EUR ? #3

Closed muratsplat closed 8 years ago

muratsplat commented 8 years ago

We have to deposit 0.01 EUR from our customer using Genesis Sdk. But returns this error in raw response

<payment_response>
  <transaction_type>sale</transaction_type>
  <status>error</status>
  <unique_id>c1cdfde6822d574c7aa9dabd4832060f</unique_id>
  <transaction_id>56e7c9dccccf2</transaction_id>
  <code>340</code>
  <technical_message>'amount' must be between 0 and 1000000000</technical_message>
  <message>Please check input data for errors!</message>
  <mode>test</mode>
  <timestamp>2016-03-15T08:37:49Z</timestamp>
  <descriptor>test</descriptor>
  <amount>0</amount>
  <currency>EUR</currency>
  <sent_to_acquirer>false</sent_to_acquirer>
</payment_response>
muratsplat commented 8 years ago

I think that the sdk can converting money currency automatically..

I have read Genesis API Documentation. I'm confused..

Amount currencies: name type description USD 100.33 Should be submitted as 10033 in the amount API field (exponent 2) EUR 3 Should be submitted as 300 in the amount API field (exponent 2) MOP 345.1 Should be submitted as 3451 in the amount API field (exponent 1) JPY 150 Should be submitted as 150 in the amount API field (exponent 0) KWD 100.333 Should be submitted as 100333 in the amount API field (exponent 3)


// Set request parameters
$genesis
    ->request()
        ->setTransactionId('43671')
        ->setUsage('40208 concert tickets')
        ->setRemoteIp('245.253.2.12')
        ->setAmount('0.01') //  for 0.01 EUR
        ->setCurrency('EUR')
        // Customer Details
        ->setCustomerEmail('emil@example.com')
        ->setCustomerPhone('1987987987987')
        // Credit Card Details
        ->setCardHolder('Emil Example')
        ->setCardNumber('4200000000000000')
        ->setExpirationMonth('01')
        ->setExpirationYear('2020')
        ->setCvv('123')
        // Billing/Invoice Details
        ->setBillingFirstName('Travis')
        ->setBillingLastName('Pastrana')
        ->setBillingAddress1('Muster Str. 12')
        ->setBillingZipCode('10178')
        ->setBillingCity('Los Angeles')
        ->setBillingState('CA')
        ->setBillingCountry('US');

try {
    // Send the request
    $genesis->execute();

    // Successfully completed the transaction - display the gateway unique id
    echo $genesis->response()->getResponseObject()->unique_id;
}
// Log/handle API errors
// Example: Declined transaction, Invalid data, Invalid configuration
catch (\Genesis\Exceptions\ErrorAPI $api) {
    echo $genesis->response()->getResponseObject()->technical_message;
}
// Log/handle invalid parameters
// Example: Empty (required) parameter
catch (\Genesis\Exceptions\ErrorParameter $parameter) {
    error_log($parameter->getMessage());
}
// Log/handle network (transport) errors
// Example: SSL verification errors, Timeouts
catch (\Genesis\Exceptions\ErrorNetwork $network) {
    error_log($network->getMessage());
}
dimitrovv commented 8 years ago

Hi Murat,

the SDK calculates automatically the supplied amount to exponent. For example if you set the amount is this way:

    $genesis
        ...
        ->setAmount('0.01')//  for 0.01 EUR
        ->setCurrency('EUR')

and you get your RequestXML using

$xmlRequest = $genesis->request()->getDocument();

you will get the following result

<payment_response>
  ...
  <amount>1</amount>
  <currency>EUR</currency>
  ...
</payment_response>

The SDK is using these methods to convert the amount to exponent and from exponent to amount.

\Genesis\Utils\Currency::amountToExponent($amount, $iso);
\Genesis\Utils\Currency::exponentToAmount($amount, $iso);

Ex.

\Genesis\Utils\Currency::amountToExponent('0.01', 'EUR'); //output -> 1
\Genesis\Utils\Currency::exponentToAmount('1', 'EUR'); //output -> 0.01

I have created a sample code for handling the Notification, when using the Asynchronous Workfrow. You can use the Reconciliation Object to retrieve the data from the Post Notification send to your Notification URL

<?php
require 'vendor/autoload.php';

// Use the Genesis Namespace
use \Genesis;

try {
    $notification = new API\Notification($_POST);

    if ($notification->isAuthentic()) {
        $notification->initReconciliation();

        $reconcile = $notification->getReconciliationObject();

        $timestamp = ($reconcile->timestamp instanceof \DateTime)
            ? $reconcile->timestamp->format('c')
            : $reconcile->timestamp;

        $data = array(
            'unique_id'         => $reconcile->unique_id,
            'type'              => $reconcile->transaction_type,
            'mode'              => $reconcile->mode,
            'status'            => $reconcile->status,
            'currency'          => $reconcile->currency,
            'amount'            => $reconcile->amount, /*amount = '0.01'; -> it will be converted from exponent*/
            'timestamp'         => $timestamp,
            'message'           => isset($reconcile->message) ? $reconcile->message : '',
            'technical_message' => isset($reconcile->technical_message) ? $reconcile->technical_message : '',
        );

        var_dump($data);
    }

    //echo $notification->renderResponse();       
}
catch (\Exception $e) {
    error_log($e->getMessage());
}
?>

I hope my post was helpful for you. if you have further questions, feel free to describe them.

Best Regards, Ventsislav Dimitrov

muratsplat commented 8 years ago

Thanks @dimitrovv , Your replay helped me to clear my mind..