本文整理汇总了PHP中Gateway::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Gateway::instance方法的具体用法?PHP Gateway::instance怎么用?PHP Gateway::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gateway
的用法示例。
在下文中一共展示了Gateway::instance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Creates a new customer transaction.
*
* @param Model_Customer_Paymentmethod $payment_method The payment method.
* @param string $amount The amount to transact.
* @param array $data Optional data.
*
* @return Model_Customer_Transaction
*/
public static function create(Model_Customer_Paymentmethod $payment_method, $amount, array $data = array())
{
$gateway_instance = Gateway::instance($payment_method->gateway, $payment_method->customer);
if ($gateway_instance) {
$external_id = $gateway_instance->transaction()->create(array('payment_method' => $payment_method, 'amount' => $amount));
if (!$external_id) {
return false;
}
} else {
$external_id = null;
}
$transaction = Model_Customer_Transaction::forge();
$transaction->customer = $payment_method->customer;
$transaction->gateway = $payment_method->gateway;
$transaction->external_id = $external_id;
$transaction->type = $payment_method->gateway->type;
$transaction->provider = $payment_method->provider;
$transaction->account = $payment_method->account;
$transaction->amount = $amount;
try {
$transaction->save();
} catch (FuelException $e) {
Log::error($e);
return false;
}
Service_Event::trigger('customer.transaction.create', $transaction->customer->seller, $transaction->to_array());
return $transaction;
}
示例2: forge
/**
* Gets a new instance of gateway $class_name.
*
* @param Model_Gateway $gateway The gateway model to use for the driver.
* @param Model_Customer $customer The customer model to use for the driver.
* @param string $class_name The class name to call on the driver.
*
* @return Gateway_Model
*/
public static function forge(Model_Gateway $gateway, Model_Customer $customer = null, $class_name)
{
$driver_name = str_replace('Gateway_', '', get_called_class());
$driver_name = str_replace('_Driver', '', $driver_name);
$class = 'Gateway_' . Str::ucwords(Inflector::denamespace($driver_name)) . '_' . Str::ucwords(Inflector::denamespace($class_name));
if (!class_exists($class)) {
throw new GatewayException('Call to undefined class ' . $class);
}
$driver = Gateway::instance($gateway, $customer);
return new $class($driver);
}
示例3: create
/**
* Creates a new customer gateway relation.
*
* @param Model_Customer $customer The customer.
* @param Model_Gateway $gateway The gateway.
* @param array $data Optional data.
*
* @return Model_Customer
*/
public static function create(Model_Customer $customer, Model_Gateway $gateway, array $data = array())
{
if (!($contact = Arr::get($data, 'contact'))) {
$contact = current($customer->contacts);
}
$external_id = Gateway::instance($gateway)->customer()->create(array('customer' => $customer, 'contact' => $contact));
if (!$external_id) {
return false;
}
$customer_gateway = Model_Customer_Gateway::forge();
$customer_gateway->customer_id = $customer->id;
$customer_gateway->gateway_id = $gateway->id;
$customer_gateway->external_id = $external_id;
try {
$customer_gateway->save();
} catch (FuelException $e) {
Log::error($e);
return false;
}
return $customer_gateway;
}
示例4: delete
/**
* Deletes a payment method.
*
* @param Model_Customer_Paymentmethod $payment_method The payment method to delete.
*
* @return bool
*/
public static function delete(Model_Customer_Paymentmethod $payment_method)
{
// A primary payment method cannot be deleted.
if ($payment_method->primary()) {
return false;
}
$gateway = $payment_method->gateway;
$customer = $payment_method->customer;
$gateway_instance = Gateway::instance($gateway, $customer);
if ($gateway_instance) {
$gateway_payment_method = $gateway_instance->paymentmethod($payment_method->external_id);
if (!$gateway_payment_method) {
return false;
}
if (!$gateway_payment_method->delete()) {
return false;
}
}
$payment_method->status = 'deleted';
try {
$payment_method->save();
} catch (FuelException $e) {
Log::error($e);
return false;
}
Service_Event::trigger('customer.paymentmethod.delete', $payment_method->customer->seller, $payment_method->to_array());
return true;
}