Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace App\Http\Controllers\Pay; use App\Exceptions\RuleValidationException; use..

Decoded Output download

<?php
namespace App\Http\Controllers\Pay;

use App\Exceptions\RuleValidationException;
use App\Http\Controllers\PayController;
use Illuminate\Http\Request;

class CoinbaseController extends PayController
{

    public function gateway(string $payway, string $orderSN)
    {
        try {
            // 
            $this->loadGateWay($orderSN, $payway);
            //
            switch ($payway) {
                case 'coinbase':
                default:
                    try {
                        $createOrderUrl="https://api.commerce.coinbase.com/charges";
                        $price_amount = sprintf('%.2f', (float)$this->order->actual_price);// 
                        $fees = (double)$this->payGateway->merchant_id;//   0.05
                        if($fees>0.00)
                        {
                            $price_amount =(double)$price_amount * (1.00+$fees);//  * 1 + 0.05
                        }


                        $redirect_url = url('detail-order-sn', ['orderSN' => $this->order->order_sn]);  //
                        $cancel_url = url('detail-order-sn', ['orderSN' => $this->order->order_sn]);  //
                        $config = [
                            'name'=>$this->order->title,
                            'description'=>$this->order->title.''.$price_amount.'',
                            'pricing_type' => 'fixed_price',
                            'local_price' => [
                                'amount' =>  $price_amount,
                                'currency' => 'CNY'
                            ],
                            'metadata' => [
                                'customer_id' =>  $this->order->order_sn,
                                'customer_name' => $this->order->title
                            ],
                            'redirect_url' =>$redirect_url,
                            'cancel_url'=> $cancel_url
                        ];
                        $header = array();
                        $header[] = 'Content-Type:application/json';
                        $header[] = 'X-CC-Api-Key:'.$this->payGateway->merchant_key; //APP key
                        $header[] = 'X-CC-Version: 2018-03-22';

                        $ch = curl_init(); //curl
                        curl_setopt($ch, CURLOPT_URL, $createOrderUrl);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
                        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($config));
                        $coinbase_json = curl_exec($ch);
                        curl_close($ch);

                        $coinbase_date=json_decode($coinbase_json,true);
                        if(is_array($coinbase_date))
                        {
                            $payment_url = $coinbase_date['data']['hosted_url'];
                        }
                        else
                        {
                            return 'fail|Coinbase';
                        }
                        return redirect()->away($payment_url);
                    } catch (\Exception $e) {
                        throw new RuleValidationException(__('dujiaoka.prompt.abnormal_payment_channel') . $e->getMessage());
                    }
                    break;
            }
        } catch (RuleValidationException $exception) {
            return $this->err($exception->getMessage());
        }
    }

    public function notifyUrl(Request $request)
    {
        $payload = file_get_contents( 'php://input' );
        $sig    = $_SERVER['HTTP_X_CC_WEBHOOK_SIGNATURE'];
		$data       = json_decode( $payload, true );
		$event_data = $data['event']['data'];
		$order = $this->orderService->detailOrderSN($event_data['metadata']['customer_id']);//
		if (!$order) {
			return 'fail';
		}
		$payGateway = $this->payService->detail($order->pay_id);
		if (!$payGateway) {
			return 'fail';
		}
        if($payGateway->pay_handleroute != 'pay/coinbase'){
            return 'fail';
        }
		$secret = $payGateway->merchant_pem;//
		$sig2 = hash_hmac( 'sha256', $payload, $secret );
        $result_str=array("confirmed","resolved");//
		if (!empty( $payload ) && ($sig === $sig2))
		{

			foreach ($event_data['payments'] as $payment) {
				//if ((strtolower($payment['status']) === 'confirmed')||(strtolower($payment['status']) === 'resolved')) {
                if(in_array(strtolower($payment['status']),$result_str)){
					$return_pay_amount = $payment['value']['local']['amount'];
					$return_currency=$payment['value']['local']['currency'];
					$return_status=strtolower($payment['status']);
				}
			}
            if($return_currency !== 'CNY')
			{
				return 'error|Notify: Wrong currency:'.$return_currency;
			}

			$bccomp = bccomp($order->actual_price, $return_pay_amount, 2); //   1
            if ($bccomp == 1) {
                throw new \Exception(__('Coinbase'));
            }
            $return_merchant_order_id = $event_data['metadata']['customer_id'];//
            $tradeid = $event_data['code'];//Coinbase
            //if($return_status === 'confirmed'||$return_status === 'resolved')
            if(in_array(strtolower($payment['status']),$result_str)) {
                $this->orderProcessService->completedOrder($return_merchant_order_id, $order->actual_price, $tradeid);// 
                return "{\"status\": 200}";
            } else {
                //
                return 'fail';
                // 
            }

        } else {
            //
            return 'fail|wrong sig';
            // 
        }


    }


}
 ?>

Did this file decode correctly?

Original Code

<?php
namespace App\Http\Controllers\Pay;

use App\Exceptions\RuleValidationException;
use App\Http\Controllers\PayController;
use Illuminate\Http\Request;

class CoinbaseController extends PayController
{

    public function gateway(string $payway, string $orderSN)
    {
        try {
            // 
            $this->loadGateWay($orderSN, $payway);
            //
            switch ($payway) {
                case 'coinbase':
                default:
                    try {
                        $createOrderUrl="https://api.commerce.coinbase.com/charges";
                        $price_amount = sprintf('%.2f', (float)$this->order->actual_price);// 
                        $fees = (double)$this->payGateway->merchant_id;//   0.05
                        if($fees>0.00)
                        {
                            $price_amount =(double)$price_amount * (1.00+$fees);//  * 1 + 0.05
                        }


                        $redirect_url = url('detail-order-sn', ['orderSN' => $this->order->order_sn]);  //
                        $cancel_url = url('detail-order-sn', ['orderSN' => $this->order->order_sn]);  //
                        $config = [
                            'name'=>$this->order->title,
                            'description'=>$this->order->title.''.$price_amount.'',
                            'pricing_type' => 'fixed_price',
                            'local_price' => [
                                'amount' =>  $price_amount,
                                'currency' => 'CNY'
                            ],
                            'metadata' => [
                                'customer_id' =>  $this->order->order_sn,
                                'customer_name' => $this->order->title
                            ],
                            'redirect_url' =>$redirect_url,
                            'cancel_url'=> $cancel_url
                        ];
                        $header = array();
                        $header[] = 'Content-Type:application/json';
                        $header[] = 'X-CC-Api-Key:'.$this->payGateway->merchant_key; //APP key
                        $header[] = 'X-CC-Version: 2018-03-22';

                        $ch = curl_init(); //curl
                        curl_setopt($ch, CURLOPT_URL, $createOrderUrl);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
                        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($config));
                        $coinbase_json = curl_exec($ch);
                        curl_close($ch);

                        $coinbase_date=json_decode($coinbase_json,true);
                        if(is_array($coinbase_date))
                        {
                            $payment_url = $coinbase_date['data']['hosted_url'];
                        }
                        else
                        {
                            return 'fail|Coinbase';
                        }
                        return redirect()->away($payment_url);
                    } catch (\Exception $e) {
                        throw new RuleValidationException(__('dujiaoka.prompt.abnormal_payment_channel') . $e->getMessage());
                    }
                    break;
            }
        } catch (RuleValidationException $exception) {
            return $this->err($exception->getMessage());
        }
    }

    public function notifyUrl(Request $request)
    {
        $payload = file_get_contents( 'php://input' );
        $sig    = $_SERVER['HTTP_X_CC_WEBHOOK_SIGNATURE'];
		$data       = json_decode( $payload, true );
		$event_data = $data['event']['data'];
		$order = $this->orderService->detailOrderSN($event_data['metadata']['customer_id']);//
		if (!$order) {
			return 'fail';
		}
		$payGateway = $this->payService->detail($order->pay_id);
		if (!$payGateway) {
			return 'fail';
		}
        if($payGateway->pay_handleroute != 'pay/coinbase'){
            return 'fail';
        }
		$secret = $payGateway->merchant_pem;//
		$sig2 = hash_hmac( 'sha256', $payload, $secret );
        $result_str=array("confirmed","resolved");//
		if (!empty( $payload ) && ($sig === $sig2))
		{

			foreach ($event_data['payments'] as $payment) {
				//if ((strtolower($payment['status']) === 'confirmed')||(strtolower($payment['status']) === 'resolved')) {
                if(in_array(strtolower($payment['status']),$result_str)){
					$return_pay_amount = $payment['value']['local']['amount'];
					$return_currency=$payment['value']['local']['currency'];
					$return_status=strtolower($payment['status']);
				}
			}
            if($return_currency !== 'CNY')
			{
				return 'error|Notify: Wrong currency:'.$return_currency;
			}

			$bccomp = bccomp($order->actual_price, $return_pay_amount, 2); //   1
            if ($bccomp == 1) {
                throw new \Exception(__('Coinbase'));
            }
            $return_merchant_order_id = $event_data['metadata']['customer_id'];//
            $tradeid = $event_data['code'];//Coinbase
            //if($return_status === 'confirmed'||$return_status === 'resolved')
            if(in_array(strtolower($payment['status']),$result_str)) {
                $this->orderProcessService->completedOrder($return_merchant_order_id, $order->actual_price, $tradeid);// 
                return "{\"status\": 200}";
            } else {
                //
                return 'fail';
                // 
            }

        } else {
            //
            return 'fail|wrong sig';
            // 
        }


    }


}

Function Calls

None

Variables

None

Stats

MD5 2f5dedeff27730d8ce8e101f8fc474ee
Eval Count 0
Decode Time 120 ms