本文整理汇总了PHP中Stripe_Customer::retrieve方法的典型用法代码示例。如果您正苦于以下问题:PHP Stripe_Customer::retrieve方法的具体用法?PHP Stripe_Customer::retrieve怎么用?PHP Stripe_Customer::retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stripe_Customer
的用法示例。
在下文中一共展示了Stripe_Customer::retrieve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Create and send the request
*
* @param array $options array of options to be send in POST request
* @return gateway_response response object
*
*/
public function send($options, $type = '')
{
$result = '';
try {
if ($type == 'subscription') {
$result = Stripe_Customer::create($options);
} elseif ($type == 'plan') {
$result = Stripe_Plan::create($options);
} elseif ($type == 'retrieve') {
$result = Stripe_Plan::retrieve($options);
} elseif ($type == 'customer') {
$result = Stripe_Customer::create($options);
} elseif ($type == 'invoice') {
$result = Stripe_InvoiceItem::create($options);
// Stripe_Customer::invoiceItems($options);
} elseif ($type == 'cancel') {
$cu = Stripe_Customer::retrieve($options['customer']);
$result = $cu->cancelSubscription();
} else {
$result = Stripe_Charge::create($options);
}
} catch (Exception $ex) {
$result = $ex;
}
$response = new stripe_response($result);
return $response;
}
示例2: run
function run()
{
//Get the data from stripe
$data_raw = file_get_contents("php://input");
$data = json_decode($data_raw);
if (!$data) {
CRM_Core_Error::Fatal("Stripe Callback: cannot json_decode data, exiting. <br /> {$data}");
}
$test_mode = !$data->livemode;
$stripe_key = CRM_Core_DAO::singleValueQuery("SELECT user_name FROM civicrm_payment_processor WHERE payment_processor_type = 'Stripe' AND is_test = '{$test_mode}'");
require_once "packages/stripe-php/lib/Stripe.php";
Stripe::setApiKey($stripe_key);
//Retrieve Event from Stripe using ID even though we already have the values now.
//This is for extra security precautions mentioned here: https://stripe.com/docs/webhooks
$stripe_event_data = Stripe_Event::retrieve($data->id);
$customer_id = $stripe_event_data->data->object->customer;
switch ($stripe_event_data->type) {
//Successful recurring payment
case 'invoice.payment_succeeded':
//Get the Stripe charge object
try {
$charge = Stripe_Charge::retrieve($stripe_event_data->data->object->charge);
} catch (Exception $e) {
CRM_Core_Error::Fatal("Failed to retrieve Stripe charge. Message: " . $e->getMessage());
break;
}
//Find the recurring contribution in CiviCRM by mapping it from Stripe
$rel_info_query = CRM_Core_DAO::executeQuery("SELECT invoice_id, end_time FROM civicrm_stripe_subscriptions WHERE customer_id = '{$customer_id}'");
if (!empty($rel_info_query)) {
$rel_info_query->fetch();
$invoice_id = $rel_info_query->invoice_id;
$end_time = $rel_info_query->end_time;
} else {
CRM_Core_Error::Fatal("Error relating this customer ({$customer_id}) to the one in civicrm_stripe_subscriptions");
}
//Compare against now + 24hrs to prevent charging 1 extra day.
$time_compare = time() + 86400;
//Fetch Civi's info about this recurring object
$recur_contrib_query = CRM_Core_DAO::executeQuery("SELECT id, contact_id, currency, contribution_status_id, is_test, contribution_type_id, payment_instrument_id, campaign_id FROM civicrm_contribution_recur WHERE invoice_id = '{$invoice_id}'");
if (!empty($recur_contrib_query)) {
$recur_contrib_query->fetch();
} else {
CRM_Core_Error::Fatal("ERROR: Stripe triggered a Webhook on an invoice not found in civicrm_contribution_recur: " . $stripe_event_data);
}
//Build some params
$stripe_customer = Stripe_Customer::retrieve($customer_id);
$recieve_date = date("Y-m-d H:i:s", $charge->created);
$total_amount = $charge->amount / 100;
$fee_amount = $charge->fee / 100;
$net_amount = $total_amount - $fee_amount;
$transaction_id = $charge->id;
$new_invoice_id = $stripe_event_data->data->object->id;
if (empty($recur_contrib_query->campaign_id)) {
$recur_contrib_query->campaign_id = 'NULL';
}
$first_contrib_check = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contribution WHERE invoice_id = '{$invoice_id}' AND contribution_status_id = '2'");
if (!empty($first_contrib_check)) {
CRM_Core_DAO::executeQuery("UPDATE civicrm_contribution SET contribution_status_id = '1' WHERE id = '{$first_contrib_check}'");
return;
}
//Create this instance of the contribution for accounting in CiviCRM
CRM_Core_DAO::executeQuery("\n \tINSERT INTO civicrm_contribution (\n \tcontact_id, contribution_type_id, payment_instrument_id, receive_date, \n \ttotal_amount, fee_amount, net_amount, trxn_id, invoice_id, currency,\n \tcontribution_recur_id, is_test, contribution_status_id, campaign_id\n \t) VALUES (\n \t'{$recur_contrib_query->contact_id}', '{$recur_contrib_query->contribution_type_id}', '{$recur_contrib_query->payment_instrument_id}', '{$recieve_date}', \n \t'{$total_amount}', '{$fee_amount}', '{$net_amount}', '{$transaction_id}', '{$new_invoice_id}', '{$recur_contrib_query->currency}', \n \t'{$recur_contrib_query->id}', '{$recur_contrib_query->is_test}', '1', {$recur_contrib_query->campaign_id}\n \t)");
if ($time_compare > $end_time) {
$end_date = date("Y-m-d H:i:s", $end_time);
//Final payment. Recurring contribution complete
$stripe_customer->cancelSubscription();
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_stripe_subscriptions WHERE invoice_id = '{$invoice_id}'");
CRM_Core_DAO::executeQuery("UPDATE civicrm_contribution_recur SET end_date = '{$end_date}', contribution_status_id = '1' WHERE invoice_id = '{$invoice_id}'");
return;
}
//Successful charge & more to come so set recurring contribution status to In Progress
if ($recur_contrib_query->contribution_status_id != 5) {
CRM_Core_DAO::executeQuery("UPDATE civicrm_contribution_recur SET contribution_status_id = 5 WHERE invoice_id = '{$invoice_id}'");
return;
}
break;
//Failed recurring payment
//Failed recurring payment
case 'invoice.payment_failed':
//Get the Stripe charge object
try {
$charge = Stripe_Charge::retrieve($stripe_event_data->data->object->charge);
} catch (Exception $e) {
CRM_Core_Error::Fatal("Failed to retrieve Stripe charge. Message: " . $e->getMessage());
break;
}
//Find the recurring contribution in CiviCRM by mapping it from Stripe
$invoice_id = CRM_Core_DAO::singleValueQuery("SELECT invoice_id FROM civicrm_stripe_subscriptions WHERE customer_id = '{$customer_id}'");
if (empty($invoice_id)) {
CRM_Core_Error::Fatal("Error relating this customer ({$customer_id}) to the one in civicrm_stripe_subscriptions");
}
//Fetch Civi's info about this recurring object
$recur_contrib_query = CRM_Core_DAO::executeQuery("SELECT id, contact_id, currency, contribution_status_id, is_test, contribution_type_id, payment_instrument_id, campaign_id FROM civicrm_contribution_recur WHERE invoice_id = '{$invoice_id}'");
if (!empty($recur_contrib_query)) {
$recur_contrib_query->fetch();
} else {
CRM_Core_Error::Fatal("ERROR: Stripe triggered a Webhook on an invoice not found in civicrm_contribution_recur: " . $stripe_event_data);
}
//Build some params
$recieve_date = date("Y-m-d H:i:s", $charge->created);
//.........这里部分代码省略.........
示例3: email_transfer_failed
function email_transfer_failed($transfer)
{
$customer = Stripe_Customer::retrieve($transfer->customer);
$subject = 'Your transfer was failed';
$headers = 'From: "Brandbits Support" <support@brandbits.com>';
mail($customer->email, $subject, message_body(), $headers);
}
示例4: updateSubscription
public static function updateSubscription($service, $customerId, $plan)
{
\Stripe::setApiKey($service['stripe']['secret_key']);
$customer = \Stripe_Customer::retrieve($customerId);
$customer->updateSubscription(array("plan" => $plan, "prorate" => true));
return ['id' => $customer->subscription->plan->id, 'name' => $customer->subscription->plan->name];
}
示例5: UpdateExistingCustomer
/**
* Function to update the customerinformation with customer id
* Cases when card expired or new card.
* @param Tokne id users strip token id
* @param user id
* @param amount to charge
* @param description
*/
public function UpdateExistingCustomer($customerId, $token, $name, $amount, $description = "")
{
$this->setAPIKey();
$cu = Stripe_Customer::retrieve($customerId);
$rr = json_decode($cu, true);
//echo'<pre>';print_r($rr);echo'</pre>';die();
$r = $rr['error']['message'];
$error_code = $rr['error']['code'];
$error_type = $rr['error']['type'];
//echo $error_code.'------------'.$error_type.'<br />';
if (empty($error_type) && empty($error_code)) {
$cu->card = $token;
if (!empty($description)) {
$cu->description = $description;
}
$cu->save();
$result = Stripe_Charge::create(array("amount" => "{$amount}", "currency" => "usd", "customer" => "{$customerId}"));
if ($result['paid'] === true) {
$result_array = array("success" => "1");
return $result_array;
} else {
return $result;
}
} else {
$result_array = array("update" => "1");
return $result_array;
}
}
示例6: testUpdateDescriptionNull
public function testUpdateDescriptionNull()
{
$customer = self::createTestCustomer(array('description' => 'foo bar'));
$customer->description = NULL;
$customer->save();
$updatedCustomer = Stripe_Customer::retrieve($customer->id);
$this->assertEqual(NULL, $updatedCustomer->description);
}
示例7: testInvalidObject
public function testInvalidObject()
{
self::authorizeFromEnv();
try {
Stripe_Customer::retrieve('invalid');
} catch (Stripe_InvalidRequestError $e) {
$this->assertEqual(404, $e->getHttpStatus());
}
}
示例8: testSave
public function testSave()
{
$customer = self::createTestCustomer();
$customer->email = 'gdb@stripe.com';
$customer->save();
$this->assertEqual($customer->email, 'gdb@stripe.com');
$customer2 = Stripe_Customer::retrieve($customer->id);
$this->assertEqual($customer->email, $customer2->email);
}
示例9: getCustomer
/**
* Get a customer
* @param string $customer_id
* @return Stripe_Customer|false
*/
public function getCustomer($customer_id = '')
{
try {
return Stripe_Customer::retrieve($customer_id);
} catch (Exception $ex) {
$this->log($ex);
return false;
}
}
示例10: testSave
public function testSave()
{
authorizeFromEnv();
$c = Stripe_Customer::create();
$c->email = 'gdb@stripe.com';
$c->bogus = 'bogus';
$c->save();
$this->assertEqual($c->email, 'gdb@stripe.com');
$this->assertNull($c['bogus']);
$c2 = Stripe_Customer::retrieve($c->id);
$this->assertEqual($c->email, $c2->email);
}
示例11: get
/**
* Get a single record by creating a WHERE clause with
* a value for your primary key
*
* @param string $primary_value The value of your primary key
* @return object
*/
public function get($customer_id)
{
try {
$ch = Stripe_Customer::retrieve($customer_id);
return $ch;
} catch (Exception $e) {
$this->error = TRUE;
$this->message = $e->getMessage();
$this->code = $e->getCode();
return FALSE;
}
}
示例12: testUpdateAllMetadata
public function testUpdateAllMetadata()
{
$customer = self::createTestCustomer();
$customer->metadata['shoe size'] = '7';
$customer->metadata['shirt size'] = 'XS';
$customer->save();
$customer->metadata = array('shirt size' => 'XL');
$customer->save();
$updatedCustomer = Stripe_Customer::retrieve($customer->id);
$this->assertEqual('XL', $updatedCustomer->metadata['shirt size']);
$this->assertFalse(isset($updatedCustomer->metadata['shoe size']));
}
示例13: testDeletion
public function testDeletion()
{
authorizeFromEnv();
$id = 'test-coupon-' . self::randomString();
$coupon = Stripe_Coupon::create(array('percent_off' => 25, 'duration' => 'repeating', 'duration_in_months' => 5, 'id' => $id));
$customer = self::createTestCustomer(array('coupon' => $id));
$this->assertTrue(isset($customer->discount));
$this->assertTrue(isset($customer->discount->coupon));
$this->assertEqual($id, $customer->discount->coupon->id);
$customer->deleteDiscount();
$this->assertFalse(isset($customer->discount));
$customer = Stripe_Customer::retrieve($customer->id);
$this->assertFalse(isset($customer->discount));
}
示例14: return_credit_cards
public function return_credit_cards()
{
try {
$this->sktest_setapikey();
$stripe_id = get_user_meta(get_current_user_id(), 'stripe_customer_id', true);
$customerret = Stripe_Customer::retrieve($stripe_id);
} catch (Stripe_Error $e) {
$body = $e->getJsonBody();
$err = $body['error'];
print $error[‘message’];
}
$idtest = $customerret->id;
echo $idtest;
}
示例15: wpestate_cancel_stripe
function wpestate_cancel_stripe()
{
global $current_user;
require_once get_template_directory() . '/libs/stripe/lib/Stripe.php';
get_currentuserinfo();
$userID = $current_user->ID;
$stripe_customer_id = get_user_meta($userID, 'stripe', true);
$subscription_id = get_user_meta($userID, 'stripe_subscription_id', true);
$stripe_secret_key = esc_html(get_option('wp_estate_stripe_secret_key', ''));
$stripe_publishable_key = esc_html(get_option('wp_estate_stripe_publishable_key', ''));
$stripe = array("secret_key" => $stripe_secret_key, "publishable_key" => $stripe_publishable_key);
Stripe::setApiKey($stripe['secret_key']);
$processor_link = wpestate_get_stripe_link();
$submission_curency_status = esc_html(get_option('wp_estate_submission_curency', ''));
$cu = Stripe_Customer::retrieve($stripe_customer_id);
$cu->subscriptions->retrieve($subscription_id)->cancel(array("at_period_end" => true));
update_user_meta($current_user->ID, 'stripe_subscription_id', '');
}