/** * Process the purchase data and send to Payeezy * * @since 1.0 * @return void */ public function process_payment($purchase_data) { global $edd_options; $url = edd_is_test_mode() ? 'https://api-cert.payeezy.com/v1/transactions' : 'https://api.payeezy.com/v1/transactions'; $payeezy = new Payeezy(); $payeezy::setApiKey(edd_get_option('payeezy_api_key')); $payeezy::setApiSecret(edd_get_option('payeezy_api_secret')); $payeezy::setMerchantToken(edd_get_option('payeezy_token')); $payeezy::setUrl($url); $month = $purchase_data['card_info']['card_exp_month']; $month = $month > 9 ? $month : '0' . $month; // Payeezy requires two digits $year = substr($purchase_data['card_info']['card_exp_year'], -2); $card_type = edd_detect_cc_type($purchase_data['card_info']['card_number']); switch ($card_type) { case 'amex': $card_type = 'American Express'; break; } $response = json_decode($payeezy->purchase(array('amount' => $purchase_data['price'], 'card_number' => $purchase_data['card_info']['card_number'], 'card_type' => $card_type, 'card_holder_name' => $purchase_data['card_info']['card_name'], 'card_cvv' => $purchase_data['card_info']['card_cvc'], 'card_expiry' => $month . $year, 'currency_code' => 'USD'))); if ('failed' === $response->validation_status) { foreach ($response->Error->messages as $error) { edd_set_error($error->code, $error->description); } edd_send_back_to_checkout('?payment-mode=payeezy'); } elseif ('success' === $response->validation_status) { if ('approved' === $response->transaction_status) { $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['post_data']['edd_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending'); // record the pending payment $payment_id = edd_insert_payment($payment_data); edd_update_payment_status($payment_id, 'publish'); edd_set_payment_transaction_id($payment_id, $response->transaction_id); // Empty the shopping cart edd_empty_cart(); edd_send_to_success_page(); } else { edd_set_error('payeezy_error', sprintf(__('Transaction not approved. Status: %s', 'edd-payeezy'), $response->transaction_status)); edd_send_back_to_checkout('?payment-mode=payeezy'); } } }
/** * Payeezy * * Generate Payload for Telecheck & Value Link */ public function getTeleCheckValueLinkPayLoad($args = array()) { $method_name = strtolower(func_get_arg(0)); //check if telecheck or valuelink if ($method_name == 'tele_check') { //Common required parameters $args = array_merge(array("billing_address" => array("street" => "", "city" => "", "state_province" => "", "zip_postal_code" => "", "country" => "")), $args); $transaction_type = strtolower(func_get_arg(1)); $data = ""; if ($transaction_type == 'purchase') { $data = array("method" => $method_name, "transaction_type" => $transaction_type, "amount" => $args['amount'], "currency_code" => $args['currency_code'], "tele_check" => array("check_number" => $args['check_number'], "check_type" => $args['check_type'], "routing_number" => $args['routing_number'], "account_number" => $args['account_number'], "accountholder_name" => $args['accountholder_name'], "customer_id_type" => $args['customer_id_type'], "customer_id_number" => $args['customer_id_number'], "client_email" => $args['client_email'], "gift_card_amount" => $args['gift_card_amount'], "vip" => $args['vip'], "clerk_id" => $args['clerk_id'], "device_id" => $args['device_id'], "micr" => $args['micr'], "release_type" => $args['release_type'], "registration_number" => $args['registration_number'], "registration_date" => $args['registration_date'], "date_of_birth" => $args['date_of_birth'])); self::$url = self::$baseURL; } else { //Not Purchase but Void/TaggedVoid/TaggedRefund self::$url = self::$baseURL . '/' . $args['transaction_id']; if ($transaction_type == "void" || $transaction_type == 'refund' && isset($args['transaction_tag'])) { $data = array("method" => $method_name, "transaction_type" => $transaction_type, "amount" => $args['amount'], "currency_code" => $args['currency_code'], "transaction_tag" => $args['transaction_tag']); } else { $data = array("method" => $method_name, "transaction_type" => $transaction_type, "amount" => $args['amount'], "currency_code" => $args['currency_code'], "tele_check" => array("check_number" => $args['check_number'], "check_type" => $args['check_type'], "routing_number" => $args['routing_number'], "account_number" => $args['account_number'], "accountholder_name" => $args['accountholder_name'], "customer_id_type" => $args['customer_id_type'], "customer_id_number" => $args['customer_id_number'], "client_email" => $args['client_email'], "gift_card_amount" => $args['gift_card_amount'], "vip" => $args['vip'], "clerk_id" => $args['clerk_id'], "device_id" => $args['device_id'], "micr" => $args['micr'], "release_type" => $args['release_type'], "registration_number" => $args['registration_number'], "registration_date" => $args['registration_date'], "date_of_birth" => $args['date_of_birth'])); } //end of void/tagged void/tagged refund } //end of purchase telecheck } else { //Common required parameters $args = array_merge(array("valuelink" => array("cardholder_name" => "", "cc_number" => "", "credit_card_type" => "", "card_cost" => "")), $args); $transaction_type = strtolower(func_get_arg(1)); $data = ""; if ($transaction_type == 'cashout' || $transaction_type == 'deactivation' || $transaction_type == 'balance_inquiry') { $data = array("method" => $method_name, "transaction_type" => $transaction_type); self::$url = self::$baseURL; } elseif ($transaction_type == 'void') { self::$url = self::$baseURL . '/' . $args['transaction_id']; $data = array("method" => $method_name, "transaction_type" => $transaction_type, "amount" => $args['amount'], "currency_code" => $args['currency_code'], "transaction_tag" => $args['transaction_tag']); } else { $data = array("transaction_type" => $transaction_type, "method" => $method_name, "amount" => $args['amount'], "currency_code" => $args['currency_code']); self::$url = self::$baseURL; } //end of valuelink methods } //end of valuelink return json_encode($data, JSON_FORCE_OBJECT); }
<?php require_once './Payeezy.php'; $payeezy = new Payeezy(); //jae's developer account // $payeezy->setApiKey("EHMenTH0KF1aN7KQpjGDsj7V9r5fxaaB"); // $payeezy->setApiSecret("243a48b691a3b8f62b4f496e67ae2a58c333729aa58dafa074f211f3eaefe4b5"); // $payeezy->setMerchantToken("fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6"); //test account provided in sample code $payeezy->setApiKey("y6pWAJNyJyjGv66IsVuWnklkKUPFbb0a"); $payeezy->setApiSecret("86fbae7030253af3cd15faef2a1f4b67353e41fb6799f576b5093ae52901e6f7"); $payeezy->setMerchantToken("fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6"); $payeezy->setTokenUrl("https://api-cert.payeezy.com/v1/transactions/tokens"); $payeezy->setUrl("https://api-cert.payeezy.com/v1/transactions"); echo "-------------------- Testing authorize 1----------"; $response = $payeezy->authorize(setTokenPayload()); echo $response; echo "<br>"; echo "<br>"; echo "-------------------- Testing authorize 2 ---------- </br> "; $response = $payeezy->authorize(setPrimaryTxPayload()); echo $response; function setTokenPayload() { $card_holder_name = $amount = $transaction_type = $auth = $card_number = $ta_token = $card_type = $card_cvv = $card_expiry = $currency_code = $merchant_ref = ""; $transaction_type = processInput("FDToken"); $auth = processInput("false"); $ta_token = processInput("NOIW"); $card_holder_name = processInput("PHP Client"); $card_number = processInput("4788250000028291"); $card_type = processInput("visa");
/** * Payeezy * * Generate Payload */ public function getPayload($args = array()) { $args = array_merge(array("amount" => "", "card_number" => "", "card_type" => "", "card_holder_name" => "", "card_cvv" => "", "card_expiry" => "", "merchant_ref" => "", "currency_code" => "", "transaction_tag" => "", "split_shipment" => "", "transaction_id" => ""), $args); $transaction_type = strtolower(func_get_arg(1)); $data = ""; if ($transaction_type == "authorize" || $transaction_type == "purchase") { $data = array('merchant_ref' => $args['merchant_ref'], 'transaction_type' => $transaction_type, 'method' => 'credit_card', 'amount' => $args['amount'], 'currency_code' => strtoupper($args['currency_code']), 'credit_card' => array('type' => $args['card_type'], 'cardholder_name' => $args['card_holder_name'], 'card_number' => $args['card_number'], 'exp_date' => $args['card_expiry'], 'cvv' => $args['card_cvv'])); self::$url = self::$baseURL; } else { self::$url = self::$baseURL . '/' . $args['transaction_id']; if ($transaction_type == "split") { $data = array('merchant_ref' => $args['merchant_ref'], 'transaction_type' => $transaction_type, 'method' => 'credit_card', 'amount' => $args['amount'], 'currency_code' => strtoupper($args['currency_code']), 'transaction_tag' => $args['transaction_tag'], 'split_shipment' => $args['split_shipment']); } else { $data = array('merchant_ref' => $args['merchant_ref'], 'transaction_type' => $transaction_type, 'method' => 'credit_card', 'amount' => $args['amount'], 'currency_code' => strtoupper($args['currency_code']), 'transaction_tag' => $args['transaction_tag']); } } return json_encode($data, JSON_FORCE_OBJECT); }
<!DOCTYPE html> <html> <head> <LINK href="payeezyCSS.css" rel="stylesheet" type="text/css"> </head> <body> <?php require_once './Payeezy.php'; $payeezy = new Payeezy(); /* https://developer.payeezy.com/tokenizedtreditcardpost/apis/post/transactions/tokens-1 POST - Tokenize Credit card Payload details : { "type": "FDToken", "credit_card": { "type": "VISA", "cardholder_name": "JohnSmith", "card_number": "4788250000028291", "exp_date": "1030", "cvv": "123" }, "auth": "false", "ta_token": "NOIW" } checkout "Header Parameters" on developer.payeezy.com For more details : https://github.com/payeezy/payeezy_js/raw/master/guide/Payeezy_TokenBased_Transactions.pdf // "auth": "true" will authorize card for $0 and return token */ function setTokenPayload()