integrate wirecard payment api

Wirecard payment is much easiest way for payment now a days. For this reason integrate wirecard payment is becoming popular day by day. Adding wirecard payment in your web application is not so very hard. To integrate wirecard payment in web application we use wirecard payment api. We send a post request with curl and find response. For Integrating just follow the below step.

Step 01 : Make a html form for sending post request and geting input data like credit card details.

<div class="row">
     <div class="col">
          <div class="form-group ">
              <label for="message">Credit Card No </label>
              <input class="form-control" type="text" name="card" placeholder="Credit Card No" value="" required="">
              <input type="hidden" name="card_type" value="" id="cardType">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <div class="form-group">
                                <label for="message">Expiry Month </label>
                                <input type="number" class="form-control" name="expiry_month" placeholder="Month" min="1" max="12" value="" required="">
                                
                            </div>
                        </div>
                        <div class="col">
                            <div class="form-group">
                                <label for="message">Expiry Year</label>
                                <input type="number" class="form-control" name="expiry_year" placeholder="Year" value="{{old('expiry_year')}}" required="">
                            </div>
                        </div>
                        <div class="col">
                            <div class="form-group ">
                                <label for="message">CVC </label>
                                <input type="number" class="form-control" name="cvv" placeholder="CVV" required="">
                                
                            </div>
                        </div>
                    </div>

Step 02: Add the following code in your controller or class file. Or Use raw php file

public function makeCreditCardRequest($request, $order_id)
    {
        $year = date('Y');
        $last_5_year = date('Y', strtotime('+5 Years'));
        $this->validate($request, [
            'card'	=> 'required|numeric',
            'expiry_month'  => 'required|integer|max:12|min:1',
            'expiry_year'  => 'required|integer|between:'.$year.','.$last_5_year,
            'cvv'=> 'required|numeric',
            'card_type'=>'required'
        ]);
        //echo config('app.credit_card_merchant_id');exit;
        $wirecardMerchantId = config('app.credit_card_merchant_id');
        $wirecardMerchantUser = config('app.credit_card_merchant_username');
        $wirecardMerchantPassword = config('app.credit_card_merchant_password');
        $authorization_base =$wirecardMerchantUser.':'.$wirecardMerchantPassword;
        $wireCardRequestID = 'add-deposit'.rand(11111, 99999).'-'.time().'-'.rand(1000, 10000).'-'.$order_id;//"fb78df4a-9784-4fea-bd3c-43953895093444";
        $amount = $request->amount;
        $currency = Currency::findOrFail($request->deposit_currency);
        $card = $request->card;//"4444333322221111";
        $card_type = $request->card_type;
        $expiry_month = $request->expiry_month; //"12";
        $expiry_year = $request->expiry_year;//"2020";
        $cvv = $request->cvv;//"123";
        $email = Auth::user()->email;
        $url = "https://api-test.wirecard.com/engine/rest/payments";
        $json_data = '{
            "payment" : {
            "merchant-account-id" : {
                "value" : "'.$wirecardMerchantId.'"
            },
            "request-id" : "'.$wireCardRequestID.'",
            "transaction-type" : "purchase",
            "requested-amount" : {
                        "value" : '.$amount.',
                        "currency" : "'.$currency->code.'"
            },
            "account-holder" : {
               "first-name" : "",
              "last-name" : "",
              "email" : "'.$email.'",
              "phone" : "",
              "address" : {
                 "street1" : "",
                "city" : "",
                "state" : "",
                "country" : ""
              }
            },
            "card" : {
              "account-number" : "'.$card.'",
              "expiration-month" : '.$expiry_month.',
              "expiration-year" : '.$expiry_year.',
              "card-security-code" : "'.$cvv.'",
              "card-type" : "'.$card_type.'"
            },
            "ip-address" : "127.0.0.1",
            "payment-methods" : {
                    "payment-method" : [ {
                        "name" : "creditcard"
              } ]
            }
          }
        }';

Step 03: Finally call the function in your request

public function processCreditCard(Request $request){
$order_id = 43534;
$response = $this->makeCreditCardRequest($request, $order_id);
            if ($response['transaction-state'] ==  "success") {
                
                flash(__('Your Deposit Request has been accepted successfully!'), 'info');

            } else {
                flash(__('Your Deposit Request can not be created!'), 'danger');
            }
            return redirect(route('mydeposits'));
}

Please make comment if you have any questions

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *