public function getTokens($options) { // Generate merchant hash code $hash = \HashGenerator::generate($this->veritrans->merchant_id, $this->veritrans->merchant_hash_key, $this->veritrans->order_id); // populate parameters for the post request $data = array('version' => $this->veritrans->version, 'merchant_id' => $this->veritrans->merchant_id, 'merchanthash' => $hash, 'order_id' => $this->veritrans->order_id, 'billing_different_with_shipping' => $this->veritrans->billing_different_with_shipping, 'required_shipping_address' => $this->veritrans->required_shipping_address, 'email' => $this->veritrans->email, 'first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'city' => $this->_sanitize($this->veritrans->city, 'city'), 'country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'phone' => $this->_sanitize($this->veritrans->phone, 'phone'), 'finish_payment_return_url' => $this->veritrans->finish_payment_return_url, 'unfinish_payment_return_url' => $this->veritrans->unfinish_payment_return_url, 'error_payment_return_url' => $this->veritrans->error_payment_return_url); if ($this->veritrans->required_shipping_address && $this->veritrans->billing_different_with_shipping) { $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->shipping_first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->shipping_last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->shipping_address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->shipping_address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->shipping_city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->shipping_country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->shipping_postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->shipping_phone, 'phone'))); } else { if ($this->veritrans->required_shipping_address && !$this->veritrans->billing_different_with_shipping) { $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->phone, 'phone'))); } } $optional_features = array('enable_3d_secure', 'bank', 'installment_terms', 'promo_bins', 'point_banks', 'payment_methods', 'installment_banks'); foreach ($optional_features as $feature) { if (!is_null($this->veritrans->{$feature})) { $data[$feature] = $this->veritrans->{$feature}; } } // Populate items $data['repeat_line'] = 0; foreach ($this->veritrans->items as $item) { $item_id[] = $this->_sanitize($item['item_id'], 'itemId'); $item_name1[] = $this->_sanitize($item['item_name1'], 'itemName'); $item_name2[] = $this->_sanitize($item['item_name2'], 'itemName'); $price[] = $this->_sanitize($item['price'], 'price'); $quantity[] = $item['quantity']; $data['repeat_line']++; } $data['item_id'] = $item_id; $data['item_name1'] = $item_name1; $data['item_name2'] = $item_name2; $data['price'] = $price; $data['quantity'] = $quantity; // Call Veritrans API try { $pest = new \PestJSON(''); $result = $pest->post(self::REQUEST_KEY_URL, $data); } catch (Exception $e) { throw $e; } // Check result if (!empty($result['token_merchant'])) { // OK return $result; } else { // Veritrans doesn't return tokens $this->veritrans->errors = $result['errors']; return false; } }
public function get_keys() { // Generate merchant hash code $hash = HashGenerator::generate($this->merchant_id, $this->merchant_hash_key, $this->settlement_type, $this->order_id, $this->gross_amount); // populate parameters for the post request $data = array('SETTLEMENT_TYPE' => '01', 'MERCHANT_ID' => $this->merchant_id, 'ORDER_ID' => $this->order_id, 'SESSION_ID' => $this->session_id, 'GROSS_AMOUNT' => $this->gross_amount, 'PREVIOUS_CUSTOMER_FLAG' => $this->previous_customer_flag, 'CUSTOMER_STATUS' => $this->customer_status, 'MERCHANTHASH' => $hash, 'PROMO_ID' => $this->promo_id, 'CUSTOMER_SPECIFICATION_FLAG' => $this->billing_address_different_with_shipping_address, 'EMAIL' => $this->email, 'FIRST_NAME' => $this->first_name, 'LAST_NAME' => $this->last_name, 'POSTAL_CODE' => $this->postal_code, 'ADDRESS1' => $this->address1, 'ADDRESS2' => $this->address2, 'CITY' => $this->city, 'COUNTRY_CODE' => $this->country_code, 'PHONE' => $this->phone, 'SHIPPING_FLAG' => $this->required_shipping_address, 'SHIPPING_FIRST_NAME' => $this->shipping_first_name, 'SHIPPING_LAST_NAME' => $this->shipping_last_name, 'SHIPPING_ADDRESS1' => $this->shipping_address1, 'SHIPPING_ADDRESS2' => $this->shipping_address2, 'SHIPPING_CITY' => $this->shipping_city, 'SHIPPING_COUNTRY_CODE' => $this->shipping_country_code, 'SHIPPING_POSTAL_CODE' => $this->shipping_postal_code, 'SHIPPING_PHONE' => $this->shipping_phone, 'SHIPPING_METHOD' => $this->shipping_method, 'CARD_NO' => $this->card_no, 'CARD_EXP_DATE' => $this->card_exp_date, 'FINISH_PAYMENT_RETURN_URL' => $this->finish_payment_return_url, 'UNFINISH_PAYMENT_RETURN_URL' => $this->unfinish_payment_return_url, 'ERROR_PAYMENT_RETURN_URL' => $this->error_payment_return_url, 'LANG_ENABLE_FLAG' => $this->lang_enable_flag, 'LANG' => $this->lang, 'enable_3d_secure' => $this->enable_3d_secure); // data query string only without commodity $query_string = http_build_query($data); // Build Commodity if (isset($this->commodity)) { $commodity_query_string = $this->build_commodity_query_string($this->commodity); $query_string = "{$query_string}&{$commodity_query_string}"; } // Build Installment Banks if (isset($this->installment_banks)) { foreach ($this->installment_banks as $bank) { $query_string = "{$query_string}&installment_banks[]={$bank}"; } } // Build Installment Terms if (isset($this->installment_terms)) { foreach ($this->installment_terms as $install) { $query_string = "{$query_string}&installment_terms[]={$install}"; } } // Build Promo Bins if (isset($this->promo_bins)) { foreach ($this->promo_bins as $bin) { $query_string = "{$query_string}&promo_bins[]={$bin}"; } } // Build Point Banks if (isset($this->point_banks)) { foreach ($this->point_banks as $bank) { $query_string = "{$query_string}&point_banks[]={$bank}"; } } $client = new Pest(self::REQUEST_KEY_URL); $result = $client->post('', $query_string); $key = $this->extract_keys_from($result); return $key; }