harrypujianto / Veritrans-Laravel5

33 stars 45 forks source link

Veritrans Error (400): Validation Error #16

Closed robertnicjoo closed 6 years ago

robertnicjoo commented 6 years ago

I try to use VtdirectController methods in my controller, the result i get is:

Veritrans Error (400): Validation Error

Codes

js

<script type="text/javascript" src="https://api.sandbox.veritrans.co.id/v2/assets/js/veritrans.min.js"></script>
<script type="text/javascript" src="{{ asset('js/jquery.fancybox.pack.js') }}"></script>
<script type="text/javascript">
        $(function(){
            Veritrans.url = "https://api.sandbox.veritrans.co.id/v2/token";
            Veritrans.client_key = "VT-client-xxx-xxxx";

            var card = function(){
                return {    'card_number'       : $(".card-number").val(),
                            'card_exp_month'    : $(".card-expiry-month").val(),
                            'card_exp_year'     : $(".card-expiry-year").val(),
                            'card_cvv'          : $(".card-cvv").val(),
                            'secure'            : false,
                            'bank'              : 'bni',
                            'gross_amount'      : 10000
                            }
            };

            function callback(response) {
                if (response.redirect_url) {
                    // 3dsecure transaction, please open this popup
                    openDialog(response.redirect_url);

                } else if (response.status_code == '200') {
                    // success 3d secure or success normal
                    closeDialog();
                    // submit form
                    // $(".submit-button").attr("disabled", "disabled");
                    $("#token_id").val(response.token_id);
                    $("#payment-form").submit();
                } else {
                    // failed request token
                    console.log('Close Dialog - failed');
                    //closeDialog();
                    //$('#purchase').removeAttr('disabled');
                    // $('#message').show(FADE_DELAY);
                    // $('#message').text(response.status_message);
                    //alert(response.status_message);
                }
            }

            function openDialog(url) {
                $.fancybox.open({
                    href: url,
                    type: 'iframe',
                    autoSize: false,
                    width: 700,
                    height: 500,
                    closeBtn: false,
                    modal: true
                });
            }

            function closeDialog() {
                $.fancybox.close();
            }

            $('.submit-button').click(function(event){
                event.preventDefault();
                //$(this).attr("disabled", "disabled"); 
                Veritrans.token(card, callback);
                return false;
            });
        });
</script>

html

<form id="payment-form" class="" action="{{url('payonline')}}" method="POST">
                          {{csrf_field()}}
                          <fieldset>
                            <legend>Checkout</legend>
                            <p>
                              <label>Card Number</label>
                              <input class="card-number" value="4011111111111112" size="20" type="text" autocomplete="off"/>
                            </p>
                            <p>
                              <label>Expiration (MM/YYYY)</label>
                              <input class="card-expiry-month" value="12" placeholder="MM" size="2" type="text" />
                                <span> / </span>
                                <input class="card-expiry-year" value="2018" placeholder="YYYY" size="4" type="text" />
                            </p>
                            <p>
                                <label>CVV</label>
                                <input class="card-cvv" value="123" size="4" type="password" autocomplete="off"/>
                            </p>

                            <p>
                                <label>Save credit card</label>
                                <input type="checkbox" name="save_cc" value="true">
                            </p>

                            <input id="token_id" name="token_id" type="hidden" />
                            <button class="submit-button" type="submit">Submit Payment</button>
                          </fieldset>
                        </form>

route

Route::post('/payonline', 'CartController@payonline');

controller

public function payonline(Request $request){
        //   midtrans
        $token = $request->input('token_id');
        $vt = new Veritrans;

        $transaction_details = array(
            'order_id'      => uniqid(),
            'gross_amount'  => $request->input('totalPriceInTotal')
        );

        $items = Cart::getContent();
        $item_details = array();
        foreach($items as $item)
        {
            $item_details[] = array(
                'id'        => $item->id,
                'price'     => $item->getPriceWithConditions(),
                'quantity'  => $item->quantity,
                'name'      => $item->name,
            );
        }

        // Populate customer's shipping address
        $shipping_address = array(
            'first_name'    => $request->input('buyer_name'),
            'last_name'     => $request->input('buyer_name'),
            'phone'         => $request->input('phone'),
            'country_code'  => 'IDN'
            );

        // Populate customer's Info
        $customer_details = array(
            'first_name'      => $request->input('buyer_name'),
            'last_name'       => $request->input('buyer_name'),
            'email'           => $request->input('buyer_email'),
            'phone'           => $request->input('phone'),
            'billing_address' => $shipping_address,
            'shipping_address'=> $shipping_address
            );

        $transaction_data = array(
            'payment_type'      => 'credit_card', 
            'credit_card'       => array(
               'token_id'  => $token,
               'bank'    => 'bni'
               ),
            'transaction_details'   => $transaction_details,
            'item_details'           => $item_details
        );

        $response = null;
        try
        {
            $response= $vt->vtdirect_charge($transaction_data);
        } 
        catch (Exception $e) 
        {
            return $e->getMessage; 
        }

        var_dump($response);
        if($response)
        {
            if($response->transaction_status == "capture")
            {
                //success
                echo "Transaksi berhasil. <br />";
                echo "Status transaksi untuk order id ".$response->order_id.": ".$response->transaction_status;

                echo "<h3>Detail transaksi:</h3>";
                var_dump($response);
            }
            else if($response->transaction_status == "deny")
            {
                //deny
                echo "Transaksi ditolak. <br />";
                echo "Status transaksi untuk order id ".$response->order_id.": ".$response->transaction_status;

                echo "<h3>Detail transaksi:</h3>";
                var_dump($response);
            }
            else if($response->transaction_status == "challenge")
            {
                //challenge
                echo "Transaksi challenge. <br />";
                echo "Status transaksi untuk order id ".$response->order_id.": ".$response->transaction_status;

                echo "<h3>Detail transaksi:</h3>";
                var_dump($response);
            }
            else
            {
                //error
                echo "Terjadi kesalahan pada data transaksi yang dikirim.<br />";
                echo "Status message: [".$response->status_code."] ".$response->status_message;

                echo "<h3>Response:</h3>";
                var_dump($response);
            }
        }
    }

Any idea why that might be?

harrypujianto commented 6 years ago

do you happen to log all the request sent to our server? if you happen to recored them, please send me the json charge request.

robertnicjoo commented 6 years ago

@harrypujianto hi, i've fixed it base on test emails i've got on snap mode. there was differences between gross_amount and items price apparently i should use same amount in both fields.

PS: vtdirect (this issue) currently working on snap mode, and for production mode i should wait for other department answer. BUT snap (which i really like to use instead of this direct) will not work even on snap mode. https://github.com/harrypujianto/Veritrans-Laravel5/issues/15

would you mind answer to that please?

thanks.