How to use wepay payment gateway in cakephp

Cakephp

Posted on 22 Aug 15 by Vickey
  767



Wepay is a best payment gateway if you want to use croudfunding. In we pay payment gateway we can hold payment and capture it later when we want.For using we pay you need to create wepay stage account and download sdk from wepay site.In this post I am integration wepay in cakephp so for using wepay with cakephp follow these steps

1.Login in wepay and download sdk for php also take your  WEPAY CLIENT ID, WEPAY CLIENT SECRET,WEPAY ACCESS TOKEN and WEPAY ACCOUNT ID and define these in your bootstrap file or in app controller

define(WEPAY_CLIENT_ID,'tertre');
define(WEPAY_CLIENT_SECRET,'tedgt435ertrtre');
define(WEPAY_ACCESS_TOKEN,'gdfgterte5455');
define(WEPAY_ACCOUNT_ID,'345345');

2. Put your wepay sdk in app/Vender directory and import it in your controller

App::import('Vendor', 'wepay/wepay');

Now you are ready to use wepay code in your actions here are some example code for make payment with wepay

In the below code payment will be on hold beacuse I used 'auto_capture'     => FALSE if you do not want it on hold you can use TRUE

App::import('Vendor', 'wepay/wepay');
public function start_payment()
{
    $client_id = WEPAY_CLIENT_ID;
    $client_secret = WEPAY_CLIENT_SECRET;
    $access_token = WEPAY_ACCESS_TOKEN;
    $account_id = WEPAY_ACCOUNT_ID;
    
    $amount=10;
    $paymentReferenceId=22; // IF YOU ARE UPDATING YOUR DATABASE IT WILL BE THE PRIMARY KEY
    
    Wepay::useStaging($client_id, $client_secret);
    $wepay = new WePay($access_token);
    $response = $wepay->request('checkout/create', array(
    
	'account_id'        => $account_id,
	'amount'            => $amount,
	'short_description' => 'We pay testing',
	'reference_id' => $paymentReferenceId,
	'type'              => 'GOODS',
	'mode'=>'iframe',
	'fee_payer' => "Payee", 
	'redirect_uri' => "PUT HERE YOUR REDIRECT URL", 
	'callback_uri' => "GIVE YOUR IPN URL", 
	'auto_capture'     => FALSE
	
    ));
    $html='';
    $html	.='<div id="paymentBox"></div>';		
    $html .='<script type="text/javascript">';
    $html .='WePay.iframe_checkout("paymentBox", "'.$response->checkout_uri.'");';
    $html .='</script>';
    
    //$this->redirect($response->checkout_uri); // YOU WILL REDIRECT ON WEPAY FOR MAKE PAYMENT
}

and this code for ipn  if you want any responce after payment or you want to save payment record in your database

public function ipn(){
    
    $client_id = WEPAY_CLIENT_ID;
    $client_secret = WEPAY_CLIENT_SECRET;
    $access_token = WEPAY_ACCESS_TOKEN;
    $account_id = WEPAY_ACCOUNT_ID;
    
    Wepay::useStaging($client_id, $client_secret);
    $wepay = new WePay($access_token);
    $checkout = $wepay->request('checkout', array(
	'checkout_id' => $_POST['checkout_id'], 
    ));
    
    $reference_Id	=	$_POST['reference_id'];
    $checkout_id	=	$_POST['checkout_id'];
    $processing_fee	=	$checkout->fee;
    
    // SAVE checkout_id TO DATABASE
   
    
}

you can capture your payment by the below code

public function capture_funds(){
    
    $client_id = WEPAY_CLIENT_ID;
    $client_secret = WEPAY_CLIENT_SECRET;
    $access_token = WEPAY_ACCESS_TOKEN;
    $account_id = WEPAY_ACCOUNT_ID;
    
    //// FETCH RECORD FROM DATABASE
    $checkout_id='FETCH RECORD FROM DATABASE';
    
    Wepay::useStaging($client_id, $client_secret);
    $wepay = new WePay($access_token);
    $response = $wepay->request('checkout/capture', array(
	'checkout_id' => $checkout_id 
    ));
    
    
}

I hope it will help you for any question or query please comment

Thanks


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com