本文整理汇总了PHP中Stripe\Charge::retrieve方法的典型用法代码示例。如果您正苦于以下问题:PHP Charge::retrieve方法的具体用法?PHP Charge::retrieve怎么用?PHP Charge::retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stripe\Charge
的用法示例。
在下文中一共展示了Charge::retrieve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: info
/**
* Gets info for a charge.
*
* @return array|null
*/
public function info()
{
if (!$this->id || !$this->stripe_customer) {
return null;
}
if (!$this->stripe_charge) {
$this->stripe_charge = Stripe_Charge::retrieve($this->id);
if ($this->stripe_customer->id != $this->stripe_charge->customer) {
return $this->stripe_charge = null;
}
}
if (!$this->stripe_charge) {
return null;
}
return array('id' => $this->id, 'created_at' => date('Y-m-d H:i:s', $this->stripe_charge->created), 'amount' => $this->stripe_charge->amount, 'paid' => $this->stripe_charge->paid, 'refunded' => $this->stripe_charge->refunded, 'captured' => $this->stripe_charge->captured, 'card' => $this->stripe_charge->source ? $this->stripe_charge->source->id : null, 'invoice_id' => $this->stripe_charge->invoice, 'description' => $this->stripe_charge->description);
}
示例2: do_charge
public function do_charge()
{
if (wp_verify_nonce($_POST['wp-simple-pay-pro-nonce'], 'charge_card')) {
global $sc_options;
$query_args = array();
// Set redirect
$redirect = $_POST['sc-redirect'];
$fail_redirect = $_POST['sc-redirect-fail'];
$failed = null;
$message = '';
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$amount = $_POST['sc-amount'];
$description = $_POST['sc-description'];
$store_name = $_POST['sc-name'];
$currency = $_POST['sc-currency'];
$details_placement = $_POST['sc-details-placement'];
$charge = null;
$sub = isset($_POST['sc_sub_id']);
$interval = isset($_POST['sc_sub_interval']) ? $_POST['sc_sub_interval'] : 'month';
$interval_count = isset($_POST['sc_sub_interval_count']) ? $_POST['sc_sub_interval_count'] : 1;
$statement_description = isset($_POST['sc_sub_statement_description']) ? $_POST['sc_sub_statement_description'] : '';
$setup_fee = isset($_POST['sc_sub_setup_fee']) ? $_POST['sc_sub_setup_fee'] : 0;
$coupon = isset($_POST['sc_coup_coupon_code']) ? $_POST['sc_coup_coupon_code'] : '';
$test_mode = isset($_POST['sc_test_mode']) ? $_POST['sc_test_mode'] : 'false';
if ($sub) {
$sub = !empty($_POST['sc_sub_id']) ? $_POST['sc_sub_id'] : 'custom';
}
Stripe_Checkout_Functions::set_key($test_mode);
$meta = array();
if (!empty($setup_fee)) {
$meta['Setup Fee'] = Stripe_Checkout_Misc::to_formatted_amount($setup_fee, $currency);
}
$meta = apply_filters('sc_meta_values', $meta);
try {
if ($sub == 'custom') {
$timestamp = time();
$plan_id = $_POST['stripeEmail'] . '_' . $amount . '_' . $timestamp;
$name = __('Subscription:', 'sc_sub') . ' ' . Stripe_Checkout_Misc::to_formatted_amount($amount, $currency) . ' ' . strtoupper($currency) . '/' . $interval;
// Create a plan
$plan_args = array('amount' => $amount, 'interval' => $interval, 'name' => $name, 'currency' => $currency, 'id' => $plan_id, 'interval_count' => $interval_count);
if (!empty($statement_description)) {
$plan_args['statement_descriptor'] = $statement_description;
}
$new_plan = \Stripe\Plan::create($plan_args);
// Create a customer and charge
$new_customer = \Stripe\Customer::create(array('email' => $_POST['stripeEmail'], 'card' => $token, 'plan' => $plan_id, 'metadata' => $meta, 'account_balance' => $setup_fee));
} else {
// Create new customer
$cust_args = array('email' => $_POST['stripeEmail'], 'card' => $token, 'plan' => $sub, 'metadata' => $meta, 'account_balance' => $setup_fee);
if (!empty($coupon)) {
$cust_args['coupon'] = $coupon;
}
$new_customer = \Stripe\Customer::create($cust_args);
// Set currency based on sub
$plan = \Stripe\Plan::retrieve($sub);
//echo $subscription . '<Br>';
$currency = strtoupper($plan->currency);
}
// We want to add the meta data and description to the actual charge so that users can still view the meta sent with a subscription + custom fields
// the same way that they would normally view it without subscriptions installed.
// We need the steps below to do this
// First we get the latest invoice based on the customer ID
$invoice = \Stripe\Invoice::all(array('customer' => $new_customer->id, 'limit' => 1));
// If this is a trial we need to skip this part since a charge is not made
$trial = $invoice->data[0]->lines->data[0]->plan->trial_period_days;
if (empty($trial) || !empty($setup_fee)) {
// Now that we have the invoice object we can get the charge ID
$inv_charge = $invoice->data[0]->charge;
// Finally, with the charge ID we can update the specific charge and inject our meta data sent from Stripe Custom Fields
$ch = \Stripe\Charge::retrieve($inv_charge);
$charge = $ch;
if (!empty($meta)) {
$ch->metadata = $meta;
}
if (!empty($description)) {
$ch->description = $description;
}
$ch->save();
$query_args = array('charge' => $ch->id, 'store_name' => urlencode($store_name));
$failed = false;
} else {
$sub_id = $invoice->data[0]->subscription;
if (!empty($description)) {
$customer = \Stripe\Customer::retrieve($new_customer->id);
$subscription = $customer->subscriptions->retrieve($sub_id);
$subscription->metadata = array('product' => $description);
$subscription->save();
}
$query_args = array('cust_id' => $new_customer->id, 'sub_id' => $sub_id, 'store_name' => urlencode($store_name));
$failed = false;
}
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
$redirect = $fail_redirect;
$failed = true;
$e = $e->getJsonBody();
$query_args = array('sub' => true, 'error_code' => $e['error']['type'], 'charge_failed' => true);
}
unset($_POST['stripeToken']);
//.........这里部分代码省略.........
示例3: stripe_traite_reponse_transaction
/**
* Gerer la reponse du POST JS sur paiement/abonnement
* @param array $config
* @param array $response
* @return array
*/
function stripe_traite_reponse_transaction($config, &$response)
{
$mode = $config['presta'];
if (isset($config['mode_test']) and $config['mode_test']) {
$mode .= "_test";
}
$config_id = bank_config_id($config);
$is_abo = (isset($response['abo']) and $response['abo']);
if (!isset($response['id_transaction']) or !isset($response['transaction_hash'])) {
return bank_transaction_invalide(0, array('mode' => $mode, 'erreur' => "transaction inconnue", 'log' => var_export($response, true)));
}
if ((!isset($response['charge_id']) or !$response['charge_id']) and (!isset($response['token']) or !$response['token'])) {
return bank_transaction_invalide(0, array('mode' => $mode, 'erreur' => "token/charge_id absent dans la reponse", 'log' => var_export($response, true)));
}
$id_transaction = $response['id_transaction'];
$transaction_hash = $response['transaction_hash'];
if (!($row = sql_fetsel('*', 'spip_transactions', 'id_transaction=' . intval($id_transaction)))) {
return bank_transaction_invalide($id_transaction, array('mode' => $mode, 'erreur' => "transaction non trouvee", 'log' => var_export($response, true)));
}
if ($transaction_hash != $row['transaction_hash']) {
return bank_transaction_invalide($id_transaction, array('mode' => $mode, 'erreur' => "hash {$transaction_hash} non conforme", 'log' => var_export($response, true)));
}
$montant = intval(round(100 * $row['montant'], 0));
if (strlen($montant) < 3) {
$montant = str_pad($montant, 3, '0', STR_PAD_LEFT);
}
$email = bank_porteur_email($row);
// ok, on traite le reglement
$date = $_SERVER['REQUEST_TIME'];
$date_paiement = date('Y-m-d H:i:s', $date);
$erreur = "";
$erreur_code = 0;
// charger l'API Stripe avec la cle
stripe_init_api($config);
// preparer le paiement
$nom_site = textebrut($GLOBALS['meta']['nom_site']);
$desc_charge = array('amount' => $montant, "currency" => "eur", "source" => $response['token'], "description" => "Transaction #" . $id_transaction . " [{$nom_site}]", "receipt_email" => $email, "metadata" => array('id_transaction' => $id_transaction, 'id_auteur' => $row['id_auteur'], 'nom_site' => $nom_site, 'url_site' => $GLOBALS['meta']['adresse_site']));
// la charge existe deja (autoresponse webhook sur abonnement)
if (isset($response['charge_id']) and $response['charge_id']) {
try {
$charge = \Stripe\Charge::retrieve($response['charge_id']);
$charge->description = $desc_charge['description'];
$charge->metadata = $desc_charge['metadata'];
$charge->save();
if (!$charge->paid) {
$erreur_code = 'unpaid';
$erreur = 'payment failed';
}
} catch (Exception $e) {
if ($body = $e->getJsonBody()) {
$err = $body['error'];
list($erreur_code, $erreur) = stripe_error_code($err);
} else {
$erreur = $e->getMessage();
$erreur_code = 'error';
}
}
} else {
// est-ce un abonnement ?
if ($is_abo) {
// on decrit l'echeance
if ($decrire_echeance = charger_fonction("decrire_echeance", "abos", true) and $echeance = $decrire_echeance($id_transaction)) {
if ($echeance['montant'] > 0) {
$montant_echeance = intval(round(100 * $echeance['montant'], 0));
if (strlen($montant_echeance) < 3) {
$montant_echeance = str_pad($montant_echeance, 3, '0', STR_PAD_LEFT);
}
$interval = 'month';
if (isset($echeance['freq']) and $echeance['freq'] == 'yearly') {
$interval = 'year';
}
$desc_plan = array('amount' => $montant_echeance, 'interval' => $interval, 'name' => "#{$id_transaction} [{$nom_site}]", 'currency' => $desc_charge['currency'], 'metadata' => $desc_charge['metadata']);
// dans tous les cas on fait preleve la premiere echeance en paiement unique
// et en faisant démarrer l'abonnement par "1 periode" en essai sans paiement
// ca permet de gerer le cas paiement initial different, et de recuperer les infos de CB dans tous les cas
$time_start = strtotime($date_paiement);
$time_paiement_1_interval = strtotime("+1 {$interval}", $time_start);
$nb_days = intval(round(($time_paiement_1_interval - $time_start) / 86400));
$desc_plan['trial_period_days'] = $nb_days;
// un id unique (sauf si on rejoue le meme paiement)
$desc_plan['id'] = md5(json_encode($desc_plan) . "-{$transaction_hash}");
try {
$plan = \Stripe\Plan::retrieve($desc_plan['id']);
} catch (Exception $e) {
// erreur si on ne retrouve pas le plan, on ignore
$plan = false;
}
try {
if (!$plan) {
$plan = \Stripe\Plan::create($desc_plan);
}
if (!$plan) {
$erreur = "Erreur creation plan d'abonnement";
$erreur_code = "plan_failed";
//.........这里部分代码省略.........
示例4: testRetrieve
public function testRetrieve()
{
authorizeFromEnv();
$c = Charge::create(array('amount' => 100, 'currency' => 'usd', 'card' => array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => 2015)));
$d = Charge::retrieve($c->id);
$this->assertEqual($d->id, $c->id);
}
示例5: refund
/**
* Payment refund
*
* @param \Magento\Payment\Model\InfoInterface $payment
* @param float $amount
* @return $this
* @throws \Magento\Framework\Validator\Exception
*/
public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
{
$transactionId = $payment->getParentTransactionId();
try {
\Stripe\Charge::retrieve($transactionId)->refund();
} catch (\Exception $e) {
$this->debugData(['transaction_id' => $transactionId, 'exception' => $e->getMessage()]);
$this->_logger->error(__('Payment refunding error.'));
throw new \Magento\Framework\Validator\Exception(__('Payment refunding error.'));
}
$payment->setTransactionId($transactionId . '-' . \Magento\Sales\Model\Order\Payment\Transaction::TYPE_REFUND)->setParentTransactionId($transactionId)->setIsTransactionClosed(1)->setShouldCloseParentTransaction(1);
return $this;
}
示例6: show_payment_details
/**
* Function to show the payment details after the purchase
*
* @since 1.0.0
*/
public static function show_payment_details($content)
{
if (in_the_loop() && is_main_query()) {
global $sc_options;
$html = '';
$test_mode = isset($_GET['test_mode']) ? 'true' : 'false';
$details_placement = isset($_GET['details_placement']) ? $_GET['details_placement'] : 'above';
$charge_response = null;
// Since this is a GET query arg I reset it here in case someone tries to submit it again with their own string written in the URL.
// This helps ensure it can only be set to below or above.
$details_placement = $details_placement == 'below' ? 'below' : 'above';
$is_above = $details_placement == 'below' ? 0 : 1;
Stripe_Checkout_Functions::set_key($test_mode);
// Successful charge output.
if (isset($_GET['charge']) && !isset($_GET['charge_failed'])) {
$charge_id = esc_html($_GET['charge']);
// https://stripe.com/docs/api/php#charges
$charge_response = \Stripe\Charge::retrieve($charge_id);
if (null === $sc_options->get_setting_value('disable_success_message')) {
$html = '<div class="sc-payment-details-wrap">' . "\n";
$html .= '<p>' . __('Congratulations. Your payment went through!', 'stripe') . '</p>' . "\n";
$html .= '<p>' . "\n";
if (!empty($charge_response->description)) {
$html .= __("Here's what you purchased:", 'stripe') . '<br/>' . "\n";
$html .= esc_html($charge_response->description) . '<br/>' . "\n";
}
if (isset($_GET['store_name']) && !empty($_GET['store_name'])) {
$html .= __('From: ', 'stripe') . esc_html($_GET['store_name']) . '<br/>' . "\n";
}
$html .= '<br/>' . "\n";
$html .= '<strong>' . __('Total Paid: ', 'stripe') . Stripe_Checkout_Misc::to_formatted_amount($charge_response->amount, $charge_response->currency) . ' ' . strtoupper($charge_response->currency) . '</strong>' . "\n";
$html .= '</p>' . "\n";
$html .= '<p>' . sprintf(__('Your transaction ID is: %s', 'stripe'), $charge_response->id) . '</p>' . "\n";
$html .= '</div>' . "\n";
if ($is_above) {
$content = apply_filters('sc_payment_details', $html, $charge_response) . $content;
} else {
$content = $content . apply_filters('sc_payment_details', $html, $charge_response);
}
}
do_action('sc_after_charge', $charge_response);
} elseif (isset($_GET['charge_failed'])) {
$charge_id = esc_html($_GET['charge']);
$charge = \Stripe\Charge::retrieve($charge_id);
// LITE ONLY: Payment details error included in payment details function.
$html = '<div class="sc-payment-details-wrap sc-payment-details-error">' . "\n";
$html .= '<p>' . __('Sorry, but there has been an error processing your payment.', 'stripe') . '</p>' . "\n";
$html .= '<p>' . $charge->failure_message . '</p>';
$html .= '</div>' . "\n";
if ($is_above) {
$content = apply_filters('sc_payment_details_error', $html) . $content;
} else {
$content = $content . apply_filters('sc_payment_details_error', $html);
}
do_action('sc_after_charge', $charge_response);
}
}
return $content;
}
示例7: request
/**
* request method
*
* @param string $method
* @param array $data
*
* @return array - containing 'status', 'message' and 'data' keys
* if response was successful, keys will be 'success', 'Success' and the stripe response as associated array respectively,
* if request failed, keys will be 'error', the card error message if it was card_error, boolen false otherwise, and
* error data as an array respectively
*/
private function request($method = null, $data = null)
{
if (!$method) {
throw new Exception(__('Request method is missing'));
}
if (is_null($data)) {
throw new Exception(__('Request Data is not provided'));
}
Stripe::setApiKey($this->key);
$success = null;
$error = null;
$message = false;
$log = null;
try {
switch ($method) {
/**
*
* CHARGES
*
*/
case 'charge':
$success = $this->fetch(Charge::create($data));
break;
case 'retrieveCharge':
$success = $this->fetch(Charge::retrieve($data['charge_id']));
if (!empty($success['refunds'])) {
foreach ($success['refunds'] as &$refund) {
$refund = $this->fetch($refund);
}
}
break;
case 'updateCharge':
$charge = Charge::retrieve($data['charge_id']);
foreach ($data['fields'] as $field => $value) {
$charge->{$field} = $value;
}
$success = $this->fetch($charge->save());
break;
case 'refundCharge':
$charge = Charge::retrieve($data['charge_id']);
// to prevent unknown param error
unset($data['charge_id']);
$success = $this->fetch($charge->refund($data));
foreach ($success['refunds']['data'] as &$refund) {
$refund = $this->fetch($refund);
}
break;
case 'captureCharge':
$charge = Charge::retrieve($data['charge_id']);
unset($data['charge_id']);
$success = $this->fetch($charge->capture($data));
if (!empty($success['refunds']['data'])) {
foreach ($success['refunds']['data'] as &$refund) {
$refund = $this->fetch($refund);
}
}
break;
case 'listCharges':
$charges = Charge::all();
$success = $this->fetch($charges);
foreach ($success['data'] as &$charge) {
$charge = $this->fetch($charge);
if (isset($charge['refunds']['data']) && !empty($charge['refunds']['data'])) {
foreach ($charge['refunds']['data'] as &$refund) {
$refund = $this->fetch($refund);
}
unset($refund);
}
}
break;
/**
* CUSTOMERS
*/
/**
* CUSTOMERS
*/
case 'createCustomer':
$customer = Customer::create($data);
$success = $this->fetch($customer);
if (!empty($success['cards']['data'])) {
foreach ($success['cards']['data'] as &$card) {
$card = $this->fetch($card);
}
unset($card);
}
if (!empty($success['subscriptions']['data'])) {
foreach ($success['subscriptions']['data'] as &$subscription) {
$subscription = $this->fetch($subscription);
}
//.........这里部分代码省略.........
示例8: retrieve
/**
* Retrieve stripe charge object
*
* @param string $id Charge StripeID
*
* @return \Stripe\Charge
*/
public function retrieve($id)
{
return StripeChargeApi::retrieve($id);
}
示例9: capture
public function capture($id)
{
Stripe::setApiKey(\Config::get('stripe.key'));
try {
$capture = StripeCharge::retrieve($id);
$capture->capture();
} catch (StripeError\Base $e) {
$errorBody = $e->getJsonBody();
echo 'Status is: ' . $e->getHttpStatus() . '<br>';
echo 'Param is: ' . $errorBody['error']['param'] . '<br>';
echo 'Message is: ' . $errorBody['error']['message'] . '<br>';
}
}
示例10: refundAction
/**
* Gets the order id, total amount, refunded positions and an optional comment
* from the request and uses them to create a new refund with Stripe.
* If successful, the information abouth the refund are added to the internal coment
* of ther order. Finally the new internal comment is added to the response.
*/
public function refundAction()
{
// Get order id, total amount, positions and comment from the request
$orderId = $this->Request()->getParam('orderId');
if ($orderId === null) {
// Missing orderId
$this->View()->success = false;
$this->View()->message = 'Required parameter "orderId" not found';
$this->Response()->setHttpResponseCode(400);
return;
}
$amount = floatval($this->Request()->getParam('amount'));
if ($amount <= 0.0) {
// Invalid amount
$this->View()->success = false;
$this->View()->message = 'Required parameter "amount" must be greater zero';
$this->Response()->setHttpResponseCode(400);
return;
}
$positions = $this->Request()->getParam('positions', array());
if (count($positions) === 0) {
// Missing positions
$this->View()->success = false;
$this->View()->message = 'Required parameter "positions" not found or empty';
$this->Response()->setHttpResponseCode(400);
return;
}
$comment = $this->Request()->getParam('comment');
// Try to get order
/** @var Shopware\Models\Order\Order $order */
$order = $this->get('models')->getRepository('Shopware\\Models\\Order\\Order')->findOneById($orderId);
if ($order === null) {
// Order does not exist
$this->View()->success = false;
$this->View()->message = 'Order with id ' . $orderId . ' not found';
$this->Response()->setHttpResponseCode(404);
return;
}
if ($order->getTransactionId() === null) {
// Order wasn't payed with Stripe
$this->View()->success = false;
$this->View()->message = 'Order with id ' . $orderId . ' has no Stripe charge';
$this->Response()->setHttpResponseCode(404);
return;
}
// Set the Stripe API key
$apiKey = $this->plugin->Config()->get('stripeSecretKey');
\Stripe\Stripe::setApiKey($apiKey);
// Load the charge and add new refund to it
try {
$charge = \Stripe\Charge::retrieve($order->getTransactionId());
$charge->refund(array('amount' => intval($amount * 100)));
} catch (Exception $e) {
// Try to get the error response
if ($e->getJsonBody() !== null) {
$body = $e->getJsonBody();
$message = $body['error']['message'];
} else {
$message = $e->getMessage();
}
$this->View()->success = false;
$this->View()->message = $message;
$this->Response()->setHttpResponseCode(500);
return;
}
// Add a new refund comment to the internal comment of the order
$internalComment = $order->getInternalComment();
$internalComment .= "\n--------------------------------------------------------------\n" . 'Stripe Rückerstattung (' . date('d.m.Y, G:i:s') . ")\n" . 'Betrag: ' . number_format($amount, 2, ',', '.') . " €\n" . "Kommentar: {$comment}\n" . "Positionen:\n";
foreach ($positions as $position) {
$price = number_format($position['price'], 2, ',', '.');
$totalPrice = number_format($position['total'], 2, ',', '.');
$internalComment .= ' - ' . $position['quantity'] . ' x ' . $position['articleNumber'] . ', je ' . $price . ' €, Gesamt: ' . $totalPrice . " €\n";
}
$internalComment .= "--------------------------------------------------------------\n";
$order->setInternalComment($internalComment);
$this->get('models')->flush($order);
// Respond with the new internal comment
$this->View()->success = true;
$this->View()->internalComment = $internalComment;
}
示例11: verify
public function verify()
{
if (!$this->initStripe()) {
return false;
}
$chargeId = $this->order->getLog('Stripe Charge ID');
if (empty($chargeId)) {
return false;
}
try {
$charge = \Stripe\Charge::retrieve($chargeId);
} catch (\Exception $e) {
$this->order->addLog('Stripe Verify Fail', $e->getMessage());
return false;
}
if ($charge && $charge['status'] === 'succeeded') {
return true;
}
return false;
}
示例12: refundCharge
public function refundCharge($id)
{
$charge = Charge::retrieve($id);
try {
return $charge->refund();
} catch (\Stripe\Error\InvalidRequest $e) {
throw new \Exception($e->getMessage());
// throw new \Exception('You cannot make the same transaction twice.');
} catch (\Stripe\Error\Base $e) {
throw new \Exception($e->getMessage());
} catch (\Exception $e) {
return $e->getMessage();
}
}
示例13: captureCharge
function captureCharge()
{
$this->setApiKey();
$charge = \Stripe\Charge::retrieve("ch_17QtQXFCflfB1pEyEMJ3vb4B");
$captured = $charge->capture();
return $captured;
}
示例14: capture
/**
* Capture the Stripe charge which was authorized during validation.
*
* @param array $auth Contains the result of the authorize() function.
* @param array $feed The feed object currently being processed.
* @param array $submission_data The customer and transaction data.
* @param array $form The form object currently being processed.
* @param array $entry The entry object currently being processed.
*
* @return array
*/
public function capture($auth, $feed, $submission_data, $form, $entry)
{
// Get Stripe charge from authorization.
$charge = \Stripe\Charge::retrieve($auth['transaction_id']);
try {
// Set charge description and metadata.
$charge->description = $this->get_payment_description($entry, $submission_data, $feed);
$metadata = $this->get_stripe_meta_data($feed, $entry, $form);
if (!empty($metadata)) {
$charge->metadata = $metadata;
}
// Save charge.
$charge->save();
/**
* Allow authorization only transactions by preventing the capture request from being made after the entry has been saved.
*
* @param bool $authorization_only Defaults to false, return true to prevent payment being captured.
* @param array $feed The feed object currently being processed.
* @param array $submission_data The customer and transaction data.
* @param array $form The form object currently being processed.
* @param array $entry The entry object currently being processed.
*
* @since 2.1.0
*/
$authorization_only = apply_filters('gform_stripe_charge_authorization_only', false, $feed, $submission_data, $form, $entry);
if ($authorization_only) {
$this->log_debug(__METHOD__ . '(): The gform_stripe_charge_authorization_only filter was used to prevent capture.');
return array();
}
// Capture the charge.
$charge = $charge->capture();
// Prepare payment details.
$payment = array('is_success' => true, 'transaction_id' => $charge->id, 'amount' => $this->get_amount_import($charge->amount, $entry['currency']), 'payment_method' => rgpost('stripe_credit_card_type'));
} catch (\Exception $e) {
// Log that charge could not be captured.
$this->log_error(__METHOD__ . '(): Unable to capture charge; ' . $e->getMessage());
// Prepare payment details.
$payment = array('is_success' => false, 'error_message' => $e->getMessage());
}
return $payment;
}
示例15: process_refund
public function process_refund($order_id, $amount = NULL, $reason = '')
{
if ($amount > 0) {
$CHARGE_ID = get_post_meta($order_id, '_transaction_id', true);
$charge = \Stripe\Charge::retrieve($CHARGE_ID);
$refund = $charge->refunds->create(array('amount' => $amount * 100, 'metadata' => array('Order #' => $order_id, 'Refund reason' => $reason)));
if ($refund) {
$repoch = $refund->created;
$rdt = new DateTime("@{$repoch}");
$rtimestamp = $rdt->format('Y-m-d H:i:s e');
$refundid = $refund->id;
$wc_order = new WC_Order($order_id);
$wc_order->add_order_note(__('Stripe Refund completed at. ' . $rtimestamp . ' with Refund ID = ' . $refundid, 'woocommerce'));
return true;
} else {
return false;
}
} else {
return false;
}
}