Created
October 23, 2014 19:29
-
-
Save albertvolkman/38a59296ae0e20880c44 to your computer and use it in GitHub Desktop.
Apply payment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Apply payment against order. | |
* | |
* @param string $order_uuid | |
* The order UUID. | |
* @param string $payment_method | |
* The pipe-delimited string representing the payment method. | |
* @param integer $amount | |
* The amount to apply to the order, without the decimal. | |
*/ | |
public function payment($order_uuid, $payment_method, $amount) | |
{ | |
// Bootstrap store. | |
$this->drupalWithUser->bootstrapStore(); | |
// Load order. | |
$order = reset(entity_uuid_load('commerce_order', array($order_uuid))); | |
$order->status = "checkout_checkout"; | |
commerce_checkout_complete($order); | |
// Load chosen payment method. | |
$payment_method = commerce_payment_method_instance_load($payment_method); | |
$method_id = $payment_method['method_id']; | |
$instance_id = $payment_method['instance_id']; | |
// Add pointer to charge. | |
$charge =& $order->commerce_order_total['und'][0]; | |
// Create a new transaction. | |
$transaction = commerce_payment_transaction_new($method_id, $order->order_id); | |
$transaction->instance_id = $instance_id; | |
$transaction->amount = $amount; | |
$transaction->currency_code = $charge['currency_code']; | |
$transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS; | |
$transaction->message = 'Method: @method'; | |
$transaction->message_variables = array('@method' => 'Members 2.0'); | |
commerce_payment_transaction_save($transaction); | |
commerce_payment_commerce_payment_transaction_insert($transaction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment