mirror of https://github.com/itflow-org/itflow
Updated Client Detail Header for better mobile fit, lots of progress on stripe pay and some other minor updates
This commit is contained in:
parent
5f30dbf9a9
commit
59ce30bd79
10
client.php
10
client.php
|
|
@ -98,14 +98,14 @@ if(isset($_GET['client_id'])){
|
|||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="col-md-3">
|
||||
<h4 class="text-secondary"><strong><?php echo $client_name; ?></strong></h4>
|
||||
<a href="//maps.<?php echo $session_map_source; ?>.com/?q=<?php echo "$client_address $client_zip"; ?>" target="_blank">
|
||||
<div class="ml-1"><?php echo $client_address; ?></div>
|
||||
<div class="ml-1"><?php echo "$client_city $client_state $client_zip"; ?></div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col border-left">
|
||||
<div class="col-md-3 border-left">
|
||||
<h4 class="text-secondary">Contact</h4>
|
||||
<?php
|
||||
if(!empty($client_email)){
|
||||
|
|
@ -131,16 +131,16 @@ if(isset($_GET['client_id'])){
|
|||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="col border-left">
|
||||
<div class="col-md-3 border-left">
|
||||
<h4 class="text-secondary">Standings</h4>
|
||||
<h6 class="ml-1">Paid <div class="text-secondary float-right">$<?php echo number_format($amount_paid,2); ?></div></h6>
|
||||
<h6 class="ml-1">Balance <div class="text-secondary float-right">$<?php echo number_format($balance,2); ?></div></h6>
|
||||
</div>
|
||||
<div class="col border-left">
|
||||
<div class="col-md-2 border-left">
|
||||
<h4 class="text-secondary">Net Terms</h4>
|
||||
<h6 class="ml-1"><?php echo $client_net_terms; ?> <small class="text-secondary">Days</small></h6>
|
||||
</div>
|
||||
<div class="col border-left">
|
||||
<div class="col-md-1 border-left">
|
||||
<div class="dropdown dropleft text-center">
|
||||
<button class="btn btn-dark btn-sm float-right" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-fw fa-ellipsis-v"></i>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,177 @@
|
|||
<?php include("header.php");
|
||||
|
||||
//Rebuild URL
|
||||
|
||||
$url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o)));
|
||||
|
||||
if(isset($_GET['p'])){
|
||||
$p = intval($_GET['p']);
|
||||
$record_from = (($p)-1)*10;
|
||||
$record_to = 10;
|
||||
}else{
|
||||
$record_from = 0;
|
||||
$record_to = 10;
|
||||
$p = 1;
|
||||
}
|
||||
|
||||
if(isset($_GET['q'])){
|
||||
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
|
||||
}else{
|
||||
$q = "";
|
||||
}
|
||||
|
||||
if(!empty($_GET['sb'])){
|
||||
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
|
||||
}else{
|
||||
$sb = "contact_name";
|
||||
}
|
||||
|
||||
if(isset($_GET['o'])){
|
||||
if($_GET['o'] == 'ASC'){
|
||||
$o = "ASC";
|
||||
$disp = "DESC";
|
||||
}else{
|
||||
$o = "DESC";
|
||||
$disp = "ASC";
|
||||
}
|
||||
}else{
|
||||
$o = "ASC";
|
||||
$disp = "DESC";
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM contacts, clients WHERE contacts.client_id = clients.client_id AND contacts.company_id = $session_company_id AND (contact_name LIKE '%$q%') ORDER BY $sb $o LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
||||
$total_found_rows = $num_rows[0];
|
||||
$total_pages = ceil($total_found_rows / 10);
|
||||
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark text-white">
|
||||
<h6 class="float-left mt-1"><i class="fa fa-users mr-2"></i>Contacts</h6>
|
||||
<button class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addContactModal"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form autocomplete="off">
|
||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
||||
<input type="hidden" name="tab" value="<?php echo $_GET['tab']; ?>">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control " name="q" value="<?php if(isset($q)){echo stripslashes($q);} ?>" placeholder="Search Contacts">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-secondary"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<hr>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-borderless table-hover">
|
||||
<thead class="text-dark <?php if($num_rows[0] == 0){ echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="text-center"><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=contact_name&o=<?php echo $disp; ?>">Name</a></th>
|
||||
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=client_name&o=<?php echo $disp; ?>">Client</a></th>
|
||||
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=contact_title&o=<?php echo $disp; ?>">Title</a></th>
|
||||
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=contact_email&o=<?php echo $disp; ?>">Email</a></th>
|
||||
<th>Phone</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$contact_id = $row['contact_id'];
|
||||
$contact_name = $row['contact_name'];
|
||||
$contact_title = $row['contact_title'];
|
||||
$contact_phone = $row['contact_phone'];
|
||||
if(strlen($contact_phone)>2){
|
||||
$contact_phone = substr($row['contact_phone'],0,3)."-".substr($row['contact_phone'],3,3)."-".substr($row['contact_phone'],6,4);
|
||||
}
|
||||
$contact_mobile = $row['contact_mobile'];
|
||||
if(strlen($contact_mobile)>2){
|
||||
$contact_mobile = substr($row['contact_mobile'],0,3)."-".substr($row['contact_mobile'],3,3)."-".substr($row['contact_mobile'],6,4);
|
||||
}
|
||||
$contact_email = $row['contact_email'];
|
||||
$contact_photo = $row['contact_photo'];
|
||||
$contact_initials = initials($contact_name);
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td class="text-center">
|
||||
<a class="text-dark" href="#" data-toggle="modal" data-target="#editContactModal<?php echo $contact_id; ?>">
|
||||
<?php if(!empty($contact_photo)){ ?>
|
||||
|
||||
<img height="48" width="48" class="img-fluid rounded-circle" src="<?php echo $contact_photo; ?>">
|
||||
|
||||
<?php }else{ ?>
|
||||
|
||||
<span class="fa-stack fa-2x">
|
||||
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
|
||||
<span class="fa fa-stack-1x text-white"><?php echo $contact_initials; ?></span>
|
||||
</span>
|
||||
<br>
|
||||
|
||||
<?php } ?>
|
||||
<div class="text-secondary"><?php echo $contact_name; ?></div>
|
||||
</a>
|
||||
</td>
|
||||
<td><?php echo $client_name; ?></td>
|
||||
<td><?php echo $contact_title; ?></td>
|
||||
<td><a href="mailto:<?php echo $contact_email; ?>"><?php echo $contact_email; ?></a></td>
|
||||
<td>
|
||||
<?php
|
||||
if(!empty($contact_phone)){
|
||||
?>
|
||||
<i class="fa fa-fw fa-phone text-secondary mr-2 mb-2"></i><?php echo $contact_phone; ?>
|
||||
<br>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if(!empty($contact_mobile)){
|
||||
?>
|
||||
<i class="fa fa-fw fa-mobile-alt text-secondary mr-2 mb-2"></i><?php echo $contact_mobile; ?>
|
||||
<br>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
<div class="dropdown dropleft text-center">
|
||||
<button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editContactModal<?php echo $contact_id; ?>">Edit</a>
|
||||
<a class="dropdown-item" href="post.php?delete_contact=<?php echo $contact_id; ?>">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php include("edit_contact_modal.php"); ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php include("pagination.php"); ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
include("add_contact_modal.php");
|
||||
include("footer.php");
|
||||
|
||||
?>
|
||||
|
|
@ -63,6 +63,15 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
|
|||
ORDER BY expense_id DESC LIMIT 5"
|
||||
);
|
||||
|
||||
//Get Total Miles Driven
|
||||
$sql_miles_driven = mysqli_query($mysqli,"SELECT SUM(trip_miles) AS total_miles FROM trips WHERE YEAR(trip_date) = $year AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql_miles_driven);
|
||||
$total_miles = $row['total_miles'];
|
||||
|
||||
//Get Total Clients added
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT('client_id') AS clients_added FROM clients WHERE YEAR(client_created_at) = $year AND company_id = $session_company_id"));
|
||||
$clients_added = $row['clients_added'];
|
||||
|
||||
?>
|
||||
|
||||
<form>
|
||||
|
|
@ -285,6 +294,22 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
|
|||
</div> <!-- .col -->
|
||||
</div> <!-- row -->
|
||||
|
||||
<div class="row mt-3">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Fun Stats
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled">
|
||||
<li>Miles Driven: <?php echo $total_miles; ?></li>
|
||||
<li>Clients Added: <?php echo $clients_added; ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- .col -->
|
||||
</div> <!-- row -->
|
||||
|
||||
|
||||
|
||||
<?php include("footer.php"); ?>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,142 @@
|
|||
<?php include("header.php");
|
||||
|
||||
//Rebuild URL
|
||||
|
||||
$url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o)));
|
||||
|
||||
if(isset($_GET['p'])){
|
||||
$p = intval($_GET['p']);
|
||||
$record_from = (($p)-1)*10;
|
||||
$record_to = 10;
|
||||
}else{
|
||||
$record_from = 0;
|
||||
$record_to = 10;
|
||||
$p = 1;
|
||||
}
|
||||
|
||||
if(isset($_GET['q'])){
|
||||
$q = mysqli_real_escape_string($mysqli,$_GET['q']);
|
||||
}else{
|
||||
$q = "";
|
||||
}
|
||||
|
||||
if(!empty($_GET['sb'])){
|
||||
$sb = mysqli_real_escape_string($mysqli,$_GET['sb']);
|
||||
}else{
|
||||
$sb = "domain_id";
|
||||
}
|
||||
|
||||
if(isset($_GET['o'])){
|
||||
if($_GET['o'] == 'ASC'){
|
||||
$o = "ASC";
|
||||
$disp = "DESC";
|
||||
}else{
|
||||
$o = "DESC";
|
||||
$disp = "ASC";
|
||||
}
|
||||
}else{
|
||||
$o = "ASC";
|
||||
$disp = "DESC";
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM domains, clients
|
||||
WHERE domains.client_id = clients.client_id AND domains.company_id = $session_company_id AND (domain_name LIKE '%$q%')
|
||||
ORDER BY $sb $o LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
||||
$total_found_rows = $num_rows[0];
|
||||
$total_pages = ceil($total_found_rows / 10);
|
||||
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark text-white">
|
||||
<h6 class="float-left mt-1"><i class="fa fa-globe"></i> Domains</h6>
|
||||
<button class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addDomainModal"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form autocomplete="off">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control " name="q" value="<?php if(isset($q)){echo stripslashes($q);} ?>" placeholder="Search Domains">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-secondary"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<hr>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-borderless table-hover">
|
||||
<thead class="text-dark <?php if($num_rows[0] == 0){ echo "d-none"; } ?>">
|
||||
<tr>
|
||||
|
||||
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=domain_name&o=<?php echo $disp; ?>">Domain</a></th>
|
||||
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=client_name&o=<?php echo $disp; ?>">Client</a></th>
|
||||
<th>Registrar</th>
|
||||
<th>WebHost</th>
|
||||
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sb; ?>&sb=domain_expire&o=<?php echo $disp; ?>">Expire</a></th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$domain_id = $row['domain_id'];
|
||||
$domain_name = $row['domain_name'];
|
||||
$domain_registrar = $row['domain_registrar'];
|
||||
$domain_webhost = $row['domain_webhost'];
|
||||
$domain_expire = $row['domain_expire'];
|
||||
$client_id = $row['client_id'];
|
||||
$client_name = $row['client_name'];
|
||||
|
||||
$sql_domain_registrar = mysqli_query($mysqli,"SELECT vendor_name FROM vendors WHERE vendor_id = $domain_registrar");
|
||||
$row = mysqli_fetch_array($sql_domain_registrar);
|
||||
$domain_registrar_name = $row['vendor_name'];
|
||||
|
||||
$sql_domain_webhost = mysqli_query($mysqli,"SELECT vendor_name FROM vendors WHERE vendor_id = $domain_webhost");
|
||||
$row = mysqli_fetch_array($sql_domain_webhost);
|
||||
$domain_webhost_name = $row['vendor_name'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editDomainModal<?php echo $domain_id; ?>"><?php echo $domain_name; ?></a></td>
|
||||
<td><?php echo $client_name; ?></td>
|
||||
<td><?php echo $domain_registrar_name; ?></td>
|
||||
<td><?php echo $domain_webhost_name; ?></td>
|
||||
<td><?php echo $domain_expire; ?></td>
|
||||
<td>
|
||||
<div class="dropdown dropleft text-center">
|
||||
<button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editDomainModal<?php echo $domain_id; ?>">Edit</a>
|
||||
<a class="dropdown-item" href="post.php?delete_domain=<?php echo $domain_id; ?>">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php include("edit_domain_modal.php"); ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php include("pagination.php"); ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
include("add_domain_modal.php");
|
||||
include("footer.php");
|
||||
|
||||
?>
|
||||
|
||||
|
|
@ -35,6 +35,7 @@
|
|||
<script src='vendor/daterangepicker/daterangepicker.js'></script>
|
||||
<script src='vendor/Inputmask/dist/inputmask.min.js'></script>
|
||||
<script src='vendor/Inputmask/dist/bindings/inputmask.binding.js'></script>
|
||||
<script src="vendor/clipboard.js/dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- Custom scripts for all pages-->
|
||||
<script src="js/sb-admin.min.js"></script>
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ $config_default_net_terms = $row['config_default_net_terms'];
|
|||
|
||||
$config_recurring_auto_send_invoice = $row['config_recurring_auto_send_invoice'];
|
||||
|
||||
$config_stripe_enable = $row['config_stripe_enable'];
|
||||
$config_stripe_publishable = $row['config_stripe_publishable'];
|
||||
$config_stripe_secret = $row['config_stripe_secret'];
|
||||
|
||||
$config_api_key = $row['config_api_key'];
|
||||
$config_base_url = $row['config_base_url'];
|
||||
$config_enable_cron = $row['config_enable_cron'];
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
|
|||
}
|
||||
$config_company_email = $row['config_company_email'];
|
||||
$config_invoice_logo = $row['config_invoice_logo'];
|
||||
$config_stripe_enable = $row['config_stripe_enable'];
|
||||
$config_stripe_publishable = $row['config_stripe_publishable'];
|
||||
$config_stripe_secret = $row['config_stripe_secret'];
|
||||
|
||||
$ip = get_ip();
|
||||
$os = get_os();
|
||||
$browser = get_web_browser();
|
||||
|
|
@ -112,9 +116,9 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
|
|||
<a class="btn btn-primary" href="#" onclick="window.print();"><i class="fa fa-fw fa-print"></i> Print</a>
|
||||
<a class="btn btn-primary" download target="_blank" href="guest_post.php?pdf_invoice=<?php echo $invoice_id; ?>&url_key=<?php echo $url_key; ?>"><i class="fa fa-fw fa-download"></i> Download PDF</a>
|
||||
<?php
|
||||
if($invoice_status != "Paid" and $invoice_status != "Cancelled" and $invoice_status != "Draft"){
|
||||
if($invoice_status != "Paid" and $invoice_status != "Cancelled" and $invoice_status != "Draft" and $config_stripe_enable == 1){
|
||||
?>
|
||||
<a class="btn btn-success" href="guest_pay.php?invoice_id=<?php echo $invoice_id; ?>"><i class="fa fa-fw fa-credit-card"></i> Pay Online (Comming Soon)</a>
|
||||
<a class="btn btn-success" href="guest_pay.php?invoice_id=<?php echo $invoice_id; ?>"><i class="fa fa-fw fa-credit-card"></i> Pay Online (Coming Soon)</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
16
post.php
16
post.php
|
|
@ -318,6 +318,22 @@ if(isset($_POST['edit_alert_settings'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_online_payment_settings'])){
|
||||
|
||||
$config_stripe_enable = intval($_POST['config_stripe_enable']);
|
||||
$config_stripe_publishable = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_stripe_publishable']));
|
||||
$config_stripe_secret = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_stripe_secret']));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_stripe_enable = $config_stripe_enable, config_stripe_publishable = '$config_stripe_publishable', config_stripe_secret = '$config_stripe_secret' WHERE company_id = $session_company_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Modified', log_description = 'Online Payment', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Online Payment Settings Updated";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
}
|
||||
|
||||
if(isset($_POST['enable_2fa'])){
|
||||
|
||||
$token = mysqli_real_escape_string($mysqli,$_POST['token']);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,14 @@
|
|||
Alerts
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php if(basename($_SERVER["REQUEST_URI"]) == "settings-online-payment.php") { echo "active"; } ?>"
|
||||
href="settings-online-payment.php">
|
||||
<i class="fa fa-fw fa-2x fa-credit-card"></i><br>
|
||||
Online Payment
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?php if(basename($_SERVER["REQUEST_URI"]) == "settings-backup.php") { echo "active"; } ?>"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
<?php include("header.php"); ?>
|
||||
|
||||
<?php include("settings-nav.php"); ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark text-white">
|
||||
<h6 class="float-left mt-1"><i class="fa fa-credit-card mr-2"></i>Online Payment</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form class="p-3" action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
|
||||
<div class="custom-control custom-switch mb-2">
|
||||
<input type="checkbox" class="custom-control-input" name="config_stripe_enable" <?php if($config_stripe_enable == 1){ echo "checked"; } ?> value="1" id="customSwitch1">
|
||||
<label class="custom-control-label" for="customSwitch1">Enable Stripe</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Publishable</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="config_stripe_publishable" placeholder="Stripe Publishable API Key" value="<?php echo $config_stripe_publishable; ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Secret</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="config_stripe_secret" placeholder="Stripe Secret API Key" value="<?php echo $config_stripe_secret; ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<button type="submit" name="edit_online_payment_settings" class="btn btn-primary">Save</button>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("footer.php");
|
||||
13
side_nav.php
13
side_nav.php
|
|
@ -90,6 +90,19 @@
|
|||
<span>Transfers</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="pagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-fw fa-cog mx-2"></i>
|
||||
<span>Client Listing</span>
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="pagesDropdown">
|
||||
<a class="dropdown-item" href="contacts.php">Contacts</a>
|
||||
<a class="dropdown-item" href="locations.php">Locations</a>
|
||||
<a class="dropdown-item" href="assets.php">Assets</a>
|
||||
<a class="dropdown-item" href="logins.php">Logins</a>
|
||||
<a class="dropdown-item" href="domains.php">Domains</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="pagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-fw fa-chart-area mx-2"></i>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"presets": [["env", {
|
||||
"targets": {
|
||||
"uglify": true
|
||||
}
|
||||
}]]
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
# Change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# We recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package.json,bower.json}]
|
||||
indent_size = 2
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
### Minimal example
|
||||
|
||||
> Fork this [JSFiddle](https://jsfiddle.net/zenorocha/5kk0eysw/) and reproduce your issue.
|
||||
|
||||
### Expected behaviour
|
||||
|
||||
I thought that by going to the page '...' and pressing the button '...' then '...' would happen.
|
||||
|
||||
### Actual behaviour
|
||||
|
||||
Instead of '...', what I saw was that '...' happened instead.
|
||||
|
||||
### Browsers affected
|
||||
|
||||
I tested on all major browsers and only IE 11 does not work.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
lib
|
||||
npm-debug.log
|
||||
bower_components
|
||||
node_modules
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "clipboard",
|
||||
"version": "2.0.4",
|
||||
"description": "Modern copy to clipboard. No Flash. Just 3kb",
|
||||
"license": "MIT",
|
||||
"main": "dist/clipboard.js",
|
||||
"ignore": [
|
||||
"/.*/",
|
||||
"/demo/",
|
||||
"/test/",
|
||||
"/.*",
|
||||
"/bower.json",
|
||||
"/karma.conf.js",
|
||||
"/src",
|
||||
"/lib"
|
||||
],
|
||||
"keywords": [
|
||||
"clipboard",
|
||||
"copy",
|
||||
"cut"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "zenorocha/clipboardjs",
|
||||
"description": "Modern copy to clipboard. No Flash. Just 3kb gzipped https://clipboardjs.com",
|
||||
"type": "component",
|
||||
"homepage": "https://clipboardjs.com/",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Zeno Rocha",
|
||||
"url": "http://zenorocha.com/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"robloach/component-installer": "*"
|
||||
},
|
||||
"extra": {
|
||||
"component": {
|
||||
"scripts": [
|
||||
"dist/clipboard.js"
|
||||
],
|
||||
"files": [
|
||||
"dist/clipboard.min.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
# Contributing guide
|
||||
|
||||
Want to contribute to Clipboard.js? Awesome!
|
||||
There are many ways you can contribute, see below.
|
||||
|
||||
## Opening issues
|
||||
|
||||
Open an issue to report bugs or to propose new features.
|
||||
|
||||
- Reporting bugs: describe the bug as clearly as you can, including steps to reproduce, what happened and what you were expecting to happen. Also include browser version, OS and other related software's (npm, Node.js, etc) versions when applicable.
|
||||
|
||||
- Proposing features: explain the proposed feature, what it should do, why it is useful, how users should use it. Give us as much info as possible so it will be easier to discuss, access and implement the proposed feature. When you're unsure about a certain aspect of the feature, feel free to leave it open for others to discuss and find an appropriate solution.
|
||||
|
||||
## Proposing pull requests
|
||||
|
||||
Pull requests are very welcome. Note that if you are going to propose drastic changes, be sure to open an issue for discussion first, to make sure that your PR will be accepted before you spend effort coding it.
|
||||
|
||||
Fork the Clipboard.js repository, clone it locally and create a branch for your proposed bug fix or new feature. Avoid working directly on the master branch.
|
||||
|
||||
Implement your bug fix or feature, write tests to cover it and make sure all tests are passing (run a final `npm test` to make sure everything is correct). Then commit your changes, push your bug fix/feature branch to the origin (your forked repo) and open a pull request to the upstream (the repository you originally forked)'s master branch.
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation is extremely important and takes a fair deal of time and effort to write and keep updated. Please submit any and all improvements you can make to the repository's docs.
|
||||
|
||||
## Known issues
|
||||
If you're using npm@3 you'll probably face some issues related to peerDependencies.
|
||||
https://github.com/npm/npm/issues/9204
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>constructor-node</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<div id="btn" data-clipboard-text="1">
|
||||
<span>Copy</span>
|
||||
</div>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard by passing a HTML element -->
|
||||
<script>
|
||||
var btn = document.getElementById('btn');
|
||||
var clipboard = new ClipboardJS(btn);
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>constructor-nodelist</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<button data-clipboard-text="1">Copy</button>
|
||||
<button data-clipboard-text="2">Copy</button>
|
||||
<button data-clipboard-text="3">Copy</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard by passing a list of HTML elements -->
|
||||
<script>
|
||||
var btns = document.querySelectorAll('button');
|
||||
var clipboard = new ClipboardJS(btns);
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>constructor-selector</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<button class="btn" data-clipboard-text="1">Copy</button>
|
||||
<button class="btn" data-clipboard-text="2">Copy</button>
|
||||
<button class="btn" data-clipboard-text="3">Copy</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard by passing a string selector -->
|
||||
<script>
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>function-target</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<button class="btn">Copy</button>
|
||||
<div>hello</div>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new ClipboardJS('.btn', {
|
||||
target: function() {
|
||||
return document.querySelector('div');
|
||||
}
|
||||
});
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>function-text</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<button class="btn">Copy</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new ClipboardJS('.btn', {
|
||||
text: function() {
|
||||
return 'to be or not to be';
|
||||
}
|
||||
});
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>target-div</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<div>hello</div>
|
||||
<button class="btn" data-clipboard-action="copy" data-clipboard-target="div">Copy</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>target-input</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<input id="foo" type="text" value="hello">
|
||||
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#foo">Copy</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>target-textarea</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<!-- 1. Define some markup -->
|
||||
<textarea id="bar">hello</textarea>
|
||||
<button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">Cut</button>
|
||||
|
||||
<!-- 2. Include library -->
|
||||
<script src="../dist/clipboard.min.js"></script>
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,978 @@
|
|||
/*!
|
||||
* clipboard.js v2.0.4
|
||||
* https://zenorocha.github.io/clipboard.js
|
||||
*
|
||||
* Licensed MIT © Zeno Rocha
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define([], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["ClipboardJS"] = factory();
|
||||
else
|
||||
root["ClipboardJS"] = factory();
|
||||
})(this, function() {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // define __esModule on exports
|
||||
/******/ __webpack_require__.r = function(exports) {
|
||||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
/******/ }
|
||||
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // create a fake namespace object
|
||||
/******/ // mode & 1: value is a module id, require it
|
||||
/******/ // mode & 2: merge all properties of value into the ns
|
||||
/******/ // mode & 4: return value when already ns object
|
||||
/******/ // mode & 8|1: behave like require
|
||||
/******/ __webpack_require__.t = function(value, mode) {
|
||||
/******/ if(mode & 1) value = __webpack_require__(value);
|
||||
/******/ if(mode & 8) return value;
|
||||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
||||
/******/ var ns = Object.create(null);
|
||||
/******/ __webpack_require__.r(ns);
|
||||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
||||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
||||
/******/ return ns;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _clipboardAction = __webpack_require__(1);
|
||||
|
||||
var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
|
||||
|
||||
var _tinyEmitter = __webpack_require__(3);
|
||||
|
||||
var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
|
||||
|
||||
var _goodListener = __webpack_require__(4);
|
||||
|
||||
var _goodListener2 = _interopRequireDefault(_goodListener);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
/**
|
||||
* Base class which takes one or more elements, adds event listeners to them,
|
||||
* and instantiates a new `ClipboardAction` on each click.
|
||||
*/
|
||||
var Clipboard = function (_Emitter) {
|
||||
_inherits(Clipboard, _Emitter);
|
||||
|
||||
/**
|
||||
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
||||
* @param {Object} options
|
||||
*/
|
||||
function Clipboard(trigger, options) {
|
||||
_classCallCheck(this, Clipboard);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this));
|
||||
|
||||
_this.resolveOptions(options);
|
||||
_this.listenClick(trigger);
|
||||
return _this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines if attributes would be resolved using internal setter functions
|
||||
* or custom functions that were passed in the constructor.
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
|
||||
_createClass(Clipboard, [{
|
||||
key: 'resolveOptions',
|
||||
value: function resolveOptions() {
|
||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
|
||||
this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
|
||||
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
|
||||
this.text = typeof options.text === 'function' ? options.text : this.defaultText;
|
||||
this.container = _typeof(options.container) === 'object' ? options.container : document.body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a click event listener to the passed trigger.
|
||||
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'listenClick',
|
||||
value: function listenClick(trigger) {
|
||||
var _this2 = this;
|
||||
|
||||
this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
|
||||
return _this2.onClick(e);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a new `ClipboardAction` on each click event.
|
||||
* @param {Event} e
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'onClick',
|
||||
value: function onClick(e) {
|
||||
var trigger = e.delegateTarget || e.currentTarget;
|
||||
|
||||
if (this.clipboardAction) {
|
||||
this.clipboardAction = null;
|
||||
}
|
||||
|
||||
this.clipboardAction = new _clipboardAction2.default({
|
||||
action: this.action(trigger),
|
||||
target: this.target(trigger),
|
||||
text: this.text(trigger),
|
||||
container: this.container,
|
||||
trigger: trigger,
|
||||
emitter: this
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Default `action` lookup function.
|
||||
* @param {Element} trigger
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'defaultAction',
|
||||
value: function defaultAction(trigger) {
|
||||
return getAttributeValue('action', trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default `target` lookup function.
|
||||
* @param {Element} trigger
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'defaultTarget',
|
||||
value: function defaultTarget(trigger) {
|
||||
var selector = getAttributeValue('target', trigger);
|
||||
|
||||
if (selector) {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the support of the given action, or all actions if no action is
|
||||
* given.
|
||||
* @param {String} [action]
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'defaultText',
|
||||
|
||||
|
||||
/**
|
||||
* Default `text` lookup function.
|
||||
* @param {Element} trigger
|
||||
*/
|
||||
value: function defaultText(trigger) {
|
||||
return getAttributeValue('text', trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy lifecycle.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'destroy',
|
||||
value: function destroy() {
|
||||
this.listener.destroy();
|
||||
|
||||
if (this.clipboardAction) {
|
||||
this.clipboardAction.destroy();
|
||||
this.clipboardAction = null;
|
||||
}
|
||||
}
|
||||
}], [{
|
||||
key: 'isSupported',
|
||||
value: function isSupported() {
|
||||
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
|
||||
|
||||
var actions = typeof action === 'string' ? [action] : action;
|
||||
var support = !!document.queryCommandSupported;
|
||||
|
||||
actions.forEach(function (action) {
|
||||
support = support && !!document.queryCommandSupported(action);
|
||||
});
|
||||
|
||||
return support;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Clipboard;
|
||||
}(_tinyEmitter2.default);
|
||||
|
||||
/**
|
||||
* Helper function to retrieve attribute value.
|
||||
* @param {String} suffix
|
||||
* @param {Element} element
|
||||
*/
|
||||
|
||||
|
||||
function getAttributeValue(suffix, element) {
|
||||
var attribute = 'data-clipboard-' + suffix;
|
||||
|
||||
if (!element.hasAttribute(attribute)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return element.getAttribute(attribute);
|
||||
}
|
||||
|
||||
module.exports = Clipboard;
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _select = __webpack_require__(2);
|
||||
|
||||
var _select2 = _interopRequireDefault(_select);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
/**
|
||||
* Inner class which performs selection from either `text` or `target`
|
||||
* properties and then executes copy or cut operations.
|
||||
*/
|
||||
var ClipboardAction = function () {
|
||||
/**
|
||||
* @param {Object} options
|
||||
*/
|
||||
function ClipboardAction(options) {
|
||||
_classCallCheck(this, ClipboardAction);
|
||||
|
||||
this.resolveOptions(options);
|
||||
this.initSelection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines base properties passed from constructor.
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
|
||||
_createClass(ClipboardAction, [{
|
||||
key: 'resolveOptions',
|
||||
value: function resolveOptions() {
|
||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
|
||||
this.action = options.action;
|
||||
this.container = options.container;
|
||||
this.emitter = options.emitter;
|
||||
this.target = options.target;
|
||||
this.text = options.text;
|
||||
this.trigger = options.trigger;
|
||||
|
||||
this.selectedText = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides which selection strategy is going to be applied based
|
||||
* on the existence of `text` and `target` properties.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'initSelection',
|
||||
value: function initSelection() {
|
||||
if (this.text) {
|
||||
this.selectFake();
|
||||
} else if (this.target) {
|
||||
this.selectTarget();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fake textarea element, sets its value from `text` property,
|
||||
* and makes a selection on it.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'selectFake',
|
||||
value: function selectFake() {
|
||||
var _this = this;
|
||||
|
||||
var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
||||
|
||||
this.removeFake();
|
||||
|
||||
this.fakeHandlerCallback = function () {
|
||||
return _this.removeFake();
|
||||
};
|
||||
this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
|
||||
|
||||
this.fakeElem = document.createElement('textarea');
|
||||
// Prevent zooming on iOS
|
||||
this.fakeElem.style.fontSize = '12pt';
|
||||
// Reset box model
|
||||
this.fakeElem.style.border = '0';
|
||||
this.fakeElem.style.padding = '0';
|
||||
this.fakeElem.style.margin = '0';
|
||||
// Move element out of screen horizontally
|
||||
this.fakeElem.style.position = 'absolute';
|
||||
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
|
||||
// Move element to the same position vertically
|
||||
var yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
||||
this.fakeElem.style.top = yPosition + 'px';
|
||||
|
||||
this.fakeElem.setAttribute('readonly', '');
|
||||
this.fakeElem.value = this.text;
|
||||
|
||||
this.container.appendChild(this.fakeElem);
|
||||
|
||||
this.selectedText = (0, _select2.default)(this.fakeElem);
|
||||
this.copyText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only removes the fake element after another click event, that way
|
||||
* a user can hit `Ctrl+C` to copy because selection still exists.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'removeFake',
|
||||
value: function removeFake() {
|
||||
if (this.fakeHandler) {
|
||||
this.container.removeEventListener('click', this.fakeHandlerCallback);
|
||||
this.fakeHandler = null;
|
||||
this.fakeHandlerCallback = null;
|
||||
}
|
||||
|
||||
if (this.fakeElem) {
|
||||
this.container.removeChild(this.fakeElem);
|
||||
this.fakeElem = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the content from element passed on `target` property.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'selectTarget',
|
||||
value: function selectTarget() {
|
||||
this.selectedText = (0, _select2.default)(this.target);
|
||||
this.copyText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the copy operation based on the current selection.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'copyText',
|
||||
value: function copyText() {
|
||||
var succeeded = void 0;
|
||||
|
||||
try {
|
||||
succeeded = document.execCommand(this.action);
|
||||
} catch (err) {
|
||||
succeeded = false;
|
||||
}
|
||||
|
||||
this.handleResult(succeeded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires an event based on the copy operation result.
|
||||
* @param {Boolean} succeeded
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'handleResult',
|
||||
value: function handleResult(succeeded) {
|
||||
this.emitter.emit(succeeded ? 'success' : 'error', {
|
||||
action: this.action,
|
||||
text: this.selectedText,
|
||||
trigger: this.trigger,
|
||||
clearSelection: this.clearSelection.bind(this)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves focus away from `target` and back to the trigger, removes current selection.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'clearSelection',
|
||||
value: function clearSelection() {
|
||||
if (this.trigger) {
|
||||
this.trigger.focus();
|
||||
}
|
||||
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
|
||||
* @param {String} action
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'destroy',
|
||||
|
||||
|
||||
/**
|
||||
* Destroy lifecycle.
|
||||
*/
|
||||
value: function destroy() {
|
||||
this.removeFake();
|
||||
}
|
||||
}, {
|
||||
key: 'action',
|
||||
set: function set() {
|
||||
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
|
||||
|
||||
this._action = action;
|
||||
|
||||
if (this._action !== 'copy' && this._action !== 'cut') {
|
||||
throw new Error('Invalid "action" value, use either "copy" or "cut"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `action` property.
|
||||
* @return {String}
|
||||
*/
|
||||
,
|
||||
get: function get() {
|
||||
return this._action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `target` property using an element
|
||||
* that will be have its content copied.
|
||||
* @param {Element} target
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'target',
|
||||
set: function set(target) {
|
||||
if (target !== undefined) {
|
||||
if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
|
||||
if (this.action === 'copy' && target.hasAttribute('disabled')) {
|
||||
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
|
||||
}
|
||||
|
||||
if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
|
||||
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
|
||||
}
|
||||
|
||||
this._target = target;
|
||||
} else {
|
||||
throw new Error('Invalid "target" value, use a valid Element');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `target` property.
|
||||
* @return {String|HTMLElement}
|
||||
*/
|
||||
,
|
||||
get: function get() {
|
||||
return this._target;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ClipboardAction;
|
||||
}();
|
||||
|
||||
module.exports = ClipboardAction;
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
function select(element) {
|
||||
var selectedText;
|
||||
|
||||
if (element.nodeName === 'SELECT') {
|
||||
element.focus();
|
||||
|
||||
selectedText = element.value;
|
||||
}
|
||||
else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
|
||||
var isReadOnly = element.hasAttribute('readonly');
|
||||
|
||||
if (!isReadOnly) {
|
||||
element.setAttribute('readonly', '');
|
||||
}
|
||||
|
||||
element.select();
|
||||
element.setSelectionRange(0, element.value.length);
|
||||
|
||||
if (!isReadOnly) {
|
||||
element.removeAttribute('readonly');
|
||||
}
|
||||
|
||||
selectedText = element.value;
|
||||
}
|
||||
else {
|
||||
if (element.hasAttribute('contenteditable')) {
|
||||
element.focus();
|
||||
}
|
||||
|
||||
var selection = window.getSelection();
|
||||
var range = document.createRange();
|
||||
|
||||
range.selectNodeContents(element);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
|
||||
selectedText = selection.toString();
|
||||
}
|
||||
|
||||
return selectedText;
|
||||
}
|
||||
|
||||
module.exports = select;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
function E () {
|
||||
// Keep this empty so it's easier to inherit from
|
||||
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
|
||||
}
|
||||
|
||||
E.prototype = {
|
||||
on: function (name, callback, ctx) {
|
||||
var e = this.e || (this.e = {});
|
||||
|
||||
(e[name] || (e[name] = [])).push({
|
||||
fn: callback,
|
||||
ctx: ctx
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
once: function (name, callback, ctx) {
|
||||
var self = this;
|
||||
function listener () {
|
||||
self.off(name, listener);
|
||||
callback.apply(ctx, arguments);
|
||||
};
|
||||
|
||||
listener._ = callback
|
||||
return this.on(name, listener, ctx);
|
||||
},
|
||||
|
||||
emit: function (name) {
|
||||
var data = [].slice.call(arguments, 1);
|
||||
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
||||
var i = 0;
|
||||
var len = evtArr.length;
|
||||
|
||||
for (i; i < len; i++) {
|
||||
evtArr[i].fn.apply(evtArr[i].ctx, data);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
off: function (name, callback) {
|
||||
var e = this.e || (this.e = {});
|
||||
var evts = e[name];
|
||||
var liveEvents = [];
|
||||
|
||||
if (evts && callback) {
|
||||
for (var i = 0, len = evts.length; i < len; i++) {
|
||||
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
|
||||
liveEvents.push(evts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove event from queue to prevent memory leak
|
||||
// Suggested by https://github.com/lazd
|
||||
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
|
||||
|
||||
(liveEvents.length)
|
||||
? e[name] = liveEvents
|
||||
: delete e[name];
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = E;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 4 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
var is = __webpack_require__(5);
|
||||
var delegate = __webpack_require__(6);
|
||||
|
||||
/**
|
||||
* Validates all params and calls the right
|
||||
* listener function based on its target type.
|
||||
*
|
||||
* @param {String|HTMLElement|HTMLCollection|NodeList} target
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listen(target, type, callback) {
|
||||
if (!target && !type && !callback) {
|
||||
throw new Error('Missing required arguments');
|
||||
}
|
||||
|
||||
if (!is.string(type)) {
|
||||
throw new TypeError('Second argument must be a String');
|
||||
}
|
||||
|
||||
if (!is.fn(callback)) {
|
||||
throw new TypeError('Third argument must be a Function');
|
||||
}
|
||||
|
||||
if (is.node(target)) {
|
||||
return listenNode(target, type, callback);
|
||||
}
|
||||
else if (is.nodeList(target)) {
|
||||
return listenNodeList(target, type, callback);
|
||||
}
|
||||
else if (is.string(target)) {
|
||||
return listenSelector(target, type, callback);
|
||||
}
|
||||
else {
|
||||
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an event listener to a HTML element
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {HTMLElement} node
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenNode(node, type, callback) {
|
||||
node.addEventListener(type, callback);
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
node.removeEventListener(type, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event listener to a list of HTML elements
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {NodeList|HTMLCollection} nodeList
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenNodeList(nodeList, type, callback) {
|
||||
Array.prototype.forEach.call(nodeList, function(node) {
|
||||
node.addEventListener(type, callback);
|
||||
});
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
Array.prototype.forEach.call(nodeList, function(node) {
|
||||
node.removeEventListener(type, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event listener to a selector
|
||||
* and returns a remove listener function.
|
||||
*
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Object}
|
||||
*/
|
||||
function listenSelector(selector, type, callback) {
|
||||
return delegate(document.body, selector, type, callback);
|
||||
}
|
||||
|
||||
module.exports = listen;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 5 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
/**
|
||||
* Check if argument is a HTML element.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.node = function(value) {
|
||||
return value !== undefined
|
||||
&& value instanceof HTMLElement
|
||||
&& value.nodeType === 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a list of HTML elements.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.nodeList = function(value) {
|
||||
var type = Object.prototype.toString.call(value);
|
||||
|
||||
return value !== undefined
|
||||
&& (type === '[object NodeList]' || type === '[object HTMLCollection]')
|
||||
&& ('length' in value)
|
||||
&& (value.length === 0 || exports.node(value[0]));
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a string.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.string = function(value) {
|
||||
return typeof value === 'string'
|
||||
|| value instanceof String;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if argument is a function.
|
||||
*
|
||||
* @param {Object} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.fn = function(value) {
|
||||
var type = Object.prototype.toString.call(value);
|
||||
|
||||
return type === '[object Function]';
|
||||
};
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 6 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
var closest = __webpack_require__(7);
|
||||
|
||||
/**
|
||||
* Delegates event to a selector.
|
||||
*
|
||||
* @param {Element} element
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @param {Boolean} useCapture
|
||||
* @return {Object}
|
||||
*/
|
||||
function _delegate(element, selector, type, callback, useCapture) {
|
||||
var listenerFn = listener.apply(this, arguments);
|
||||
|
||||
element.addEventListener(type, listenerFn, useCapture);
|
||||
|
||||
return {
|
||||
destroy: function() {
|
||||
element.removeEventListener(type, listenerFn, useCapture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates event to a selector.
|
||||
*
|
||||
* @param {Element|String|Array} [elements]
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @param {Boolean} useCapture
|
||||
* @return {Object}
|
||||
*/
|
||||
function delegate(elements, selector, type, callback, useCapture) {
|
||||
// Handle the regular Element usage
|
||||
if (typeof elements.addEventListener === 'function') {
|
||||
return _delegate.apply(null, arguments);
|
||||
}
|
||||
|
||||
// Handle Element-less usage, it defaults to global delegation
|
||||
if (typeof type === 'function') {
|
||||
// Use `document` as the first parameter, then apply arguments
|
||||
// This is a short way to .unshift `arguments` without running into deoptimizations
|
||||
return _delegate.bind(null, document).apply(null, arguments);
|
||||
}
|
||||
|
||||
// Handle Selector-based usage
|
||||
if (typeof elements === 'string') {
|
||||
elements = document.querySelectorAll(elements);
|
||||
}
|
||||
|
||||
// Handle Array-like based usage
|
||||
return Array.prototype.map.call(elements, function (element) {
|
||||
return _delegate(element, selector, type, callback, useCapture);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds closest match and invokes callback.
|
||||
*
|
||||
* @param {Element} element
|
||||
* @param {String} selector
|
||||
* @param {String} type
|
||||
* @param {Function} callback
|
||||
* @return {Function}
|
||||
*/
|
||||
function listener(element, selector, type, callback) {
|
||||
return function(e) {
|
||||
e.delegateTarget = closest(e.target, selector);
|
||||
|
||||
if (e.delegateTarget) {
|
||||
callback.call(element, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = delegate;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 7 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
var DOCUMENT_NODE_TYPE = 9;
|
||||
|
||||
/**
|
||||
* A polyfill for Element.matches()
|
||||
*/
|
||||
if (typeof Element !== 'undefined' && !Element.prototype.matches) {
|
||||
var proto = Element.prototype;
|
||||
|
||||
proto.matches = proto.matchesSelector ||
|
||||
proto.mozMatchesSelector ||
|
||||
proto.msMatchesSelector ||
|
||||
proto.oMatchesSelector ||
|
||||
proto.webkitMatchesSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the closest parent that matches a selector.
|
||||
*
|
||||
* @param {Element} element
|
||||
* @param {String} selector
|
||||
* @return {Function}
|
||||
*/
|
||||
function closest (element, selector) {
|
||||
while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
|
||||
if (typeof element.matches === 'function' &&
|
||||
element.matches(selector)) {
|
||||
return element;
|
||||
}
|
||||
element = element.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = closest;
|
||||
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,31 @@
|
|||
var webpackConfig = require('./webpack.config.js');
|
||||
|
||||
module.exports = function (karma) {
|
||||
karma.set({
|
||||
plugins: ['karma-webpack', 'karma-chai', 'karma-sinon', 'karma-mocha', 'karma-phantomjs-launcher'],
|
||||
|
||||
frameworks: ['chai', 'sinon', 'mocha'],
|
||||
|
||||
files: [
|
||||
'src/**/*.js',
|
||||
'test/**/*.js',
|
||||
'./node_modules/phantomjs-polyfill/bind-polyfill.js'
|
||||
],
|
||||
|
||||
preprocessors: {
|
||||
'src/**/*.js': ['webpack'],
|
||||
'test/**/*.js': ['webpack']
|
||||
},
|
||||
|
||||
webpack: {
|
||||
module: webpackConfig.module,
|
||||
plugins: webpackConfig.plugins
|
||||
},
|
||||
|
||||
webpackMiddleware: {
|
||||
stats: 'errors-only'
|
||||
},
|
||||
|
||||
browsers: ['PhantomJS']
|
||||
});
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,12 @@
|
|||
// Package metadata for Meteor.js.
|
||||
|
||||
Package.describe({
|
||||
name: "zenorocha:clipboard",
|
||||
summary: "Modern copy to clipboard. No Flash. Just 3kb.",
|
||||
version: "2.0.4",
|
||||
git: "https://github.com/zenorocha/clipboard.js"
|
||||
});
|
||||
|
||||
Package.onUse(function(api) {
|
||||
api.addFiles("dist/clipboard.js", "client");
|
||||
});
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"name": "clipboard",
|
||||
"version": "2.0.4",
|
||||
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
||||
"repository": "zenorocha/clipboard.js",
|
||||
"license": "MIT",
|
||||
"main": "dist/clipboard.js",
|
||||
"keywords": [
|
||||
"clipboard",
|
||||
"copy",
|
||||
"cut"
|
||||
],
|
||||
"dependencies": {
|
||||
"good-listener": "^1.2.2",
|
||||
"select": "^1.1.2",
|
||||
"tiny-emitter": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-loader": "^7.1.4",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"chai": "^4.2.0",
|
||||
"cross-env": "^5.2.0",
|
||||
"karma": "^3.1.1",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-mocha": "^1.2.0",
|
||||
"karma-phantomjs-launcher": "^1.0.0",
|
||||
"karma-sinon": "^1.0.4",
|
||||
"karma-webpack": "^3.0.5",
|
||||
"mocha": "^5.2.0",
|
||||
"phantomjs-prebuilt": "^2.1.4",
|
||||
"sinon": "^7.1.1",
|
||||
"uglifyjs-webpack-plugin": "^2.0.1",
|
||||
"webpack": "^4.5.0",
|
||||
"webpack-cli": "^3.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build-debug && npm run build-min",
|
||||
"build-debug": "webpack",
|
||||
"build-min": "cross-env NODE_ENV=production webpack",
|
||||
"build-watch": "webpack --watch",
|
||||
"test": "karma start --single-run",
|
||||
"prepublish": "npm run build"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
# clipboard.js
|
||||
|
||||
[](https://travis-ci.org/zenorocha/clipboard.js)
|
||||

|
||||
|
||||
> Modern copy to clipboard. No Flash. Just 3kb gzipped.
|
||||
|
||||
<a href="https://clipboardjs.com/"><img width="728" src="https://cloud.githubusercontent.com/assets/398893/16165747/a0f6fc46-349a-11e6-8c9b-c5fd58d9099c.png" alt="Demo"></a>
|
||||
|
||||
## Why
|
||||
|
||||
Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.
|
||||
|
||||
That's why clipboard.js exists.
|
||||
|
||||
## Install
|
||||
|
||||
You can get it on npm.
|
||||
|
||||
```
|
||||
npm install clipboard --save
|
||||
```
|
||||
|
||||
Or if you're not into package management, just [download a ZIP](https://github.com/zenorocha/clipboard.js/archive/master.zip) file.
|
||||
|
||||
## Setup
|
||||
|
||||
First, include the script located on the `dist` folder or load it from [a third-party CDN provider](https://github.com/zenorocha/clipboard.js/wiki/CDN-Providers).
|
||||
|
||||
```html
|
||||
<script src="dist/clipboard.min.js"></script>
|
||||
```
|
||||
|
||||
Now, you need to instantiate it by [passing a DOM selector](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-selector.html#L18), [HTML element](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-node.html#L16-L17), or [list of HTML elements](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-nodelist.html#L18-L19).
|
||||
|
||||
```js
|
||||
new ClipboardJS('.btn');
|
||||
```
|
||||
|
||||
Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guess what? If you have hundreds of matches, this operation can consume a lot of memory.
|
||||
|
||||
For this reason we use [event delegation](http://stackoverflow.com/questions/1687296/what-is-dom-event-delegation) which replaces multiple event listeners with just a single listener. After all, [#perfmatters](https://twitter.com/hashtag/perfmatters).
|
||||
|
||||
# Usage
|
||||
|
||||
We're living a _declarative renaissance_, that's why we decided to take advantage of [HTML5 data attributes](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes) for better usability.
|
||||
|
||||
### Copy text from another element
|
||||
|
||||
A pretty common use case is to copy content from another element. You can do that by adding a `data-clipboard-target` attribute in your trigger element.
|
||||
|
||||
The value you include on this attribute needs to match another's element selector.
|
||||
|
||||
<a href="https://clipboardjs.com/#example-target"><img width="473" alt="example-2" src="https://cloud.githubusercontent.com/assets/398893/9983467/a4946aaa-5fb1-11e5-9780-f09fcd7ca6c8.png"></a>
|
||||
|
||||
```html
|
||||
<!-- Target -->
|
||||
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git">
|
||||
|
||||
<!-- Trigger -->
|
||||
<button class="btn" data-clipboard-target="#foo">
|
||||
<img src="assets/clippy.svg" alt="Copy to clipboard">
|
||||
</button>
|
||||
```
|
||||
|
||||
### Cut text from another element
|
||||
|
||||
Additionally, you can define a `data-clipboard-action` attribute to specify if you want to either `copy` or `cut` content.
|
||||
|
||||
If you omit this attribute, `copy` will be used by default.
|
||||
|
||||
<a href="https://clipboardjs.com/#example-action"><img width="473" alt="example-3" src="https://cloud.githubusercontent.com/assets/398893/10000358/7df57b9c-6050-11e5-9cd1-fbc51d2fd0a7.png"></a>
|
||||
|
||||
```html
|
||||
<!-- Target -->
|
||||
<textarea id="bar">Mussum ipsum cacilds...</textarea>
|
||||
|
||||
<!-- Trigger -->
|
||||
<button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">
|
||||
Cut to clipboard
|
||||
</button>
|
||||
```
|
||||
|
||||
As you may expect, the `cut` action only works on `<input>` or `<textarea>` elements.
|
||||
|
||||
### Copy text from attribute
|
||||
|
||||
Truth is, you don't even need another element to copy its content from. You can just include a `data-clipboard-text` attribute in your trigger element.
|
||||
|
||||
<a href="https://clipboardjs.com/#example-text"><img width="147" alt="example-1" src="https://cloud.githubusercontent.com/assets/398893/10000347/6e16cf8c-6050-11e5-9883-1c5681f9ec45.png"></a>
|
||||
|
||||
```html
|
||||
<!-- Trigger -->
|
||||
<button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">
|
||||
Copy to clipboard
|
||||
</button>
|
||||
```
|
||||
|
||||
## Events
|
||||
|
||||
There are cases where you'd like to show some user feedback or capture what has been selected after a copy/cut operation.
|
||||
|
||||
That's why we fire custom events such as `success` and `error` for you to listen and implement your custom logic.
|
||||
|
||||
```js
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.info('Action:', e.action);
|
||||
console.info('Text:', e.text);
|
||||
console.info('Trigger:', e.trigger);
|
||||
|
||||
e.clearSelection();
|
||||
});
|
||||
|
||||
clipboard.on('error', function(e) {
|
||||
console.error('Action:', e.action);
|
||||
console.error('Trigger:', e.trigger);
|
||||
});
|
||||
```
|
||||
|
||||
For a live demonstration, go to this [site](https://clipboardjs.com/) and open your console.
|
||||
|
||||
## Tooltips
|
||||
|
||||
Each application has different design needs, that's why clipboard.js does not include any CSS or built-in tooltip solution.
|
||||
|
||||
The tooltips you see on the [demo site](https://clipboardjs.com/) were built using [GitHub's Primer](https://primer.style/css/components/tooltips). You may want to check that out if you're looking for a similar look and feel.
|
||||
|
||||
## Advanced Options
|
||||
|
||||
If you don't want to modify your HTML, there's a pretty handy imperative API for you to use. All you need to do is declare a function, do your thing, and return a value.
|
||||
|
||||
For instance, if you want to dynamically set a `target`, you'll need to return a Node.
|
||||
|
||||
```js
|
||||
new ClipboardJS('.btn', {
|
||||
target: function(trigger) {
|
||||
return trigger.nextElementSibling;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
If you want to dynamically set a `text`, you'll return a String.
|
||||
|
||||
```js
|
||||
new ClipboardJS('.btn', {
|
||||
text: function(trigger) {
|
||||
return trigger.getAttribute('aria-label');
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the `container` value.
|
||||
|
||||
```js
|
||||
new ClipboardJS('.btn', {
|
||||
container: document.getElementById('modal')
|
||||
});
|
||||
```
|
||||
|
||||
Also, if you are working with single page apps, you may want to manage the lifecycle of the DOM more precisely. Here's how you clean up the events and objects that we create.
|
||||
|
||||
```js
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
clipboard.destroy();
|
||||
```
|
||||
|
||||
## Browser Support
|
||||
|
||||
This library relies on both [Selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection) and [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) APIs. The first one is [supported by all browsers](http://caniuse.com/#search=selection) while the second one is supported in the following browsers.
|
||||
|
||||
| <img src="https://clipboardjs.com/assets/images/chrome.png" width="48px" height="48px" alt="Chrome logo"> | <img src="https://clipboardjs.com/assets/images/edge.png" width="48px" height="48px" alt="Edge logo"> | <img src="https://clipboardjs.com/assets/images/firefox.png" width="48px" height="48px" alt="Firefox logo"> | <img src="https://clipboardjs.com/assets/images/ie.png" width="48px" height="48px" alt="Internet Explorer logo"> | <img src="https://clipboardjs.com/assets/images/opera.png" width="48px" height="48px" alt="Opera logo"> | <img src="https://clipboardjs.com/assets/images/safari.png" width="48px" height="48px" alt="Safari logo"> |
|
||||
|:---:|:---:|:---:|:---:|:---:|:---:|
|
||||
| 42+ ✔ | 12+ ✔ | 41+ ✔ | 9+ ✔ | 29+ ✔ | 10+ ✔ |
|
||||
|
||||
The good news is that clipboard.js gracefully degrades if you need to support older browsers. All you have to do is show a tooltip saying `Copied!` when `success` event is called and `Press Ctrl+C to copy` when `error` event is called because the text is already selected.
|
||||
|
||||
You can also check if clipboard.js is supported or not by running `ClipboardJS.isSupported()`, that way you can hide copy/cut buttons from the UI.
|
||||
|
||||
## Bonus
|
||||
|
||||
A browser extension that adds a "copy to clipboard" button to every code block on *GitHub, MDN, Gist, StackOverflow, StackExchange, npm, and even Medium.*
|
||||
|
||||
Install for [Chrome](https://chrome.google.com/webstore/detail/codecopy/fkbfebkcoelajmhanocgppanfoojcdmg) and [Firefox](https://addons.mozilla.org/en-US/firefox/addon/codecopy/).
|
||||
|
||||
## License
|
||||
|
||||
[MIT License](http://zenorocha.mit-license.org/) © Zeno Rocha
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
import select from 'select';
|
||||
|
||||
/**
|
||||
* Inner class which performs selection from either `text` or `target`
|
||||
* properties and then executes copy or cut operations.
|
||||
*/
|
||||
class ClipboardAction {
|
||||
/**
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(options) {
|
||||
this.resolveOptions(options);
|
||||
this.initSelection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines base properties passed from constructor.
|
||||
* @param {Object} options
|
||||
*/
|
||||
resolveOptions(options = {}) {
|
||||
this.action = options.action;
|
||||
this.container = options.container;
|
||||
this.emitter = options.emitter;
|
||||
this.target = options.target;
|
||||
this.text = options.text;
|
||||
this.trigger = options.trigger;
|
||||
|
||||
this.selectedText = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides which selection strategy is going to be applied based
|
||||
* on the existence of `text` and `target` properties.
|
||||
*/
|
||||
initSelection() {
|
||||
if (this.text) {
|
||||
this.selectFake();
|
||||
}
|
||||
else if (this.target) {
|
||||
this.selectTarget();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fake textarea element, sets its value from `text` property,
|
||||
* and makes a selection on it.
|
||||
*/
|
||||
selectFake() {
|
||||
const isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
||||
|
||||
this.removeFake();
|
||||
|
||||
this.fakeHandlerCallback = () => this.removeFake();
|
||||
this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
|
||||
|
||||
this.fakeElem = document.createElement('textarea');
|
||||
// Prevent zooming on iOS
|
||||
this.fakeElem.style.fontSize = '12pt';
|
||||
// Reset box model
|
||||
this.fakeElem.style.border = '0';
|
||||
this.fakeElem.style.padding = '0';
|
||||
this.fakeElem.style.margin = '0';
|
||||
// Move element out of screen horizontally
|
||||
this.fakeElem.style.position = 'absolute';
|
||||
this.fakeElem.style[ isRTL ? 'right' : 'left' ] = '-9999px';
|
||||
// Move element to the same position vertically
|
||||
let yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
||||
this.fakeElem.style.top = `${yPosition}px`;
|
||||
|
||||
this.fakeElem.setAttribute('readonly', '');
|
||||
this.fakeElem.value = this.text;
|
||||
|
||||
this.container.appendChild(this.fakeElem);
|
||||
|
||||
this.selectedText = select(this.fakeElem);
|
||||
this.copyText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only removes the fake element after another click event, that way
|
||||
* a user can hit `Ctrl+C` to copy because selection still exists.
|
||||
*/
|
||||
removeFake() {
|
||||
if (this.fakeHandler) {
|
||||
this.container.removeEventListener('click', this.fakeHandlerCallback);
|
||||
this.fakeHandler = null;
|
||||
this.fakeHandlerCallback = null;
|
||||
}
|
||||
|
||||
if (this.fakeElem) {
|
||||
this.container.removeChild(this.fakeElem);
|
||||
this.fakeElem = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the content from element passed on `target` property.
|
||||
*/
|
||||
selectTarget() {
|
||||
this.selectedText = select(this.target);
|
||||
this.copyText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the copy operation based on the current selection.
|
||||
*/
|
||||
copyText() {
|
||||
let succeeded;
|
||||
|
||||
try {
|
||||
succeeded = document.execCommand(this.action);
|
||||
}
|
||||
catch (err) {
|
||||
succeeded = false;
|
||||
}
|
||||
|
||||
this.handleResult(succeeded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires an event based on the copy operation result.
|
||||
* @param {Boolean} succeeded
|
||||
*/
|
||||
handleResult(succeeded) {
|
||||
this.emitter.emit(succeeded ? 'success' : 'error', {
|
||||
action: this.action,
|
||||
text: this.selectedText,
|
||||
trigger: this.trigger,
|
||||
clearSelection: this.clearSelection.bind(this)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves focus away from `target` and back to the trigger, removes current selection.
|
||||
*/
|
||||
clearSelection() {
|
||||
if (this.trigger) {
|
||||
this.trigger.focus();
|
||||
}
|
||||
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
|
||||
* @param {String} action
|
||||
*/
|
||||
set action(action = 'copy') {
|
||||
this._action = action;
|
||||
|
||||
if (this._action !== 'copy' && this._action !== 'cut') {
|
||||
throw new Error('Invalid "action" value, use either "copy" or "cut"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `action` property.
|
||||
* @return {String}
|
||||
*/
|
||||
get action() {
|
||||
return this._action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `target` property using an element
|
||||
* that will be have its content copied.
|
||||
* @param {Element} target
|
||||
*/
|
||||
set target(target) {
|
||||
if (target !== undefined) {
|
||||
if (target && typeof target === 'object' && target.nodeType === 1) {
|
||||
if (this.action === 'copy' && target.hasAttribute('disabled')) {
|
||||
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
|
||||
}
|
||||
|
||||
if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
|
||||
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
|
||||
}
|
||||
|
||||
this._target = target;
|
||||
}
|
||||
else {
|
||||
throw new Error('Invalid "target" value, use a valid Element');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `target` property.
|
||||
* @return {String|HTMLElement}
|
||||
*/
|
||||
get target() {
|
||||
return this._target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy lifecycle.
|
||||
*/
|
||||
destroy() {
|
||||
this.removeFake();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClipboardAction;
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
import ClipboardAction from './clipboard-action';
|
||||
import Emitter from 'tiny-emitter';
|
||||
import listen from 'good-listener';
|
||||
|
||||
/**
|
||||
* Base class which takes one or more elements, adds event listeners to them,
|
||||
* and instantiates a new `ClipboardAction` on each click.
|
||||
*/
|
||||
class Clipboard extends Emitter {
|
||||
/**
|
||||
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(trigger, options) {
|
||||
super();
|
||||
|
||||
this.resolveOptions(options);
|
||||
this.listenClick(trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines if attributes would be resolved using internal setter functions
|
||||
* or custom functions that were passed in the constructor.
|
||||
* @param {Object} options
|
||||
*/
|
||||
resolveOptions(options = {}) {
|
||||
this.action = (typeof options.action === 'function') ? options.action : this.defaultAction;
|
||||
this.target = (typeof options.target === 'function') ? options.target : this.defaultTarget;
|
||||
this.text = (typeof options.text === 'function') ? options.text : this.defaultText;
|
||||
this.container = (typeof options.container === 'object') ? options.container : document.body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a click event listener to the passed trigger.
|
||||
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
||||
*/
|
||||
listenClick(trigger) {
|
||||
this.listener = listen(trigger, 'click', (e) => this.onClick(e));
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a new `ClipboardAction` on each click event.
|
||||
* @param {Event} e
|
||||
*/
|
||||
onClick(e) {
|
||||
const trigger = e.delegateTarget || e.currentTarget;
|
||||
|
||||
if (this.clipboardAction) {
|
||||
this.clipboardAction = null;
|
||||
}
|
||||
|
||||
this.clipboardAction = new ClipboardAction({
|
||||
action : this.action(trigger),
|
||||
target : this.target(trigger),
|
||||
text : this.text(trigger),
|
||||
container : this.container,
|
||||
trigger : trigger,
|
||||
emitter : this
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Default `action` lookup function.
|
||||
* @param {Element} trigger
|
||||
*/
|
||||
defaultAction(trigger) {
|
||||
return getAttributeValue('action', trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default `target` lookup function.
|
||||
* @param {Element} trigger
|
||||
*/
|
||||
defaultTarget(trigger) {
|
||||
const selector = getAttributeValue('target', trigger);
|
||||
|
||||
if (selector) {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the support of the given action, or all actions if no action is
|
||||
* given.
|
||||
* @param {String} [action]
|
||||
*/
|
||||
static isSupported(action = ['copy', 'cut']) {
|
||||
const actions = (typeof action === 'string') ? [action] : action;
|
||||
let support = !!document.queryCommandSupported;
|
||||
|
||||
actions.forEach((action) => {
|
||||
support = support && !!document.queryCommandSupported(action);
|
||||
});
|
||||
|
||||
return support;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default `text` lookup function.
|
||||
* @param {Element} trigger
|
||||
*/
|
||||
defaultText(trigger) {
|
||||
return getAttributeValue('text', trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy lifecycle.
|
||||
*/
|
||||
destroy() {
|
||||
this.listener.destroy();
|
||||
|
||||
if (this.clipboardAction) {
|
||||
this.clipboardAction.destroy();
|
||||
this.clipboardAction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to retrieve attribute value.
|
||||
* @param {String} suffix
|
||||
* @param {Element} element
|
||||
*/
|
||||
function getAttributeValue(suffix, element) {
|
||||
const attribute = `data-clipboard-${suffix}`;
|
||||
|
||||
if (!element.hasAttribute(attribute)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return element.getAttribute(attribute);
|
||||
}
|
||||
|
||||
module.exports = Clipboard;
|
||||
|
|
@ -0,0 +1,243 @@
|
|||
import ClipboardAction from '../src/clipboard-action';
|
||||
import Emitter from 'tiny-emitter';
|
||||
|
||||
describe('ClipboardAction', () => {
|
||||
before(() => {
|
||||
global.input = document.createElement('input');
|
||||
global.input.setAttribute('id', 'input');
|
||||
global.input.setAttribute('value', 'abc');
|
||||
document.body.appendChild(global.input);
|
||||
|
||||
global.paragraph = document.createElement('p');
|
||||
global.paragraph.setAttribute('id', 'paragraph');
|
||||
global.paragraph.textContent = 'abc';
|
||||
document.body.appendChild(global.paragraph);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('#resolveOptions', () => {
|
||||
it('should set base properties', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'foo'
|
||||
});
|
||||
|
||||
assert.property(clip, 'action');
|
||||
assert.property(clip, 'container');
|
||||
assert.property(clip, 'emitter');
|
||||
assert.property(clip, 'target');
|
||||
assert.property(clip, 'text');
|
||||
assert.property(clip, 'trigger');
|
||||
assert.property(clip, 'selectedText');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#initSelection', () => {
|
||||
it('should set the position right style property', done => {
|
||||
// Set document direction
|
||||
document.documentElement.setAttribute('dir', 'rtl');
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'foo'
|
||||
});
|
||||
|
||||
assert.equal(clip.fakeElem.style.right, '-9999px');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#set action', () => {
|
||||
it('should throw an error since "action" is invalid', done => {
|
||||
try {
|
||||
new ClipboardAction({
|
||||
text: 'foo',
|
||||
action: 'paste'
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
assert.equal(e.message, 'Invalid "action" value, use either "copy" or "cut"');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#set target', () => {
|
||||
it('should throw an error since "target" do not match any element', done => {
|
||||
try {
|
||||
new ClipboardAction({
|
||||
target: document.querySelector('#foo')
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
assert.equal(e.message, 'Invalid "target" value, use a valid Element');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#selectText', () => {
|
||||
it('should create a fake element and select its value', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah'
|
||||
});
|
||||
|
||||
assert.equal(clip.selectedText, clip.fakeElem.value);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeFake', () => {
|
||||
it('should remove a temporary fake element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah'
|
||||
});
|
||||
|
||||
clip.removeFake();
|
||||
|
||||
assert.equal(clip.fakeElem, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#selectTarget', () => {
|
||||
it('should select text from editable element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
assert.equal(clip.selectedText, clip.target.value);
|
||||
});
|
||||
|
||||
it('should select text from non-editable element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#paragraph')
|
||||
});
|
||||
|
||||
assert.equal(clip.selectedText, clip.target.textContent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#copyText', () => {
|
||||
before(() => {
|
||||
global.stub = sinon.stub(document, 'execCommand');
|
||||
});
|
||||
|
||||
after(() => {
|
||||
global.stub.restore();
|
||||
});
|
||||
|
||||
it('should fire a success event on browsers that support copy command', done => {
|
||||
global.stub.returns(true);
|
||||
|
||||
let emitter = new Emitter();
|
||||
|
||||
emitter.on('success', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
});
|
||||
|
||||
it('should fire an error event on browsers that support copy command', done => {
|
||||
global.stub.returns(false);
|
||||
|
||||
let emitter = new Emitter();
|
||||
|
||||
emitter.on('error', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#handleResult', () => {
|
||||
it('should fire a success event with certain properties', done => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
clip.emitter.on('success', (e) => {
|
||||
assert.property(e, 'action');
|
||||
assert.property(e, 'text');
|
||||
assert.property(e, 'trigger');
|
||||
assert.property(e, 'clearSelection');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
clip.handleResult(true);
|
||||
});
|
||||
|
||||
it('should fire a error event with certain properties', done => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
clip.emitter.on('error', (e) => {
|
||||
assert.property(e, 'action');
|
||||
assert.property(e, 'trigger');
|
||||
assert.property(e, 'clearSelection');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
clip.handleResult(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clearSelection', () => {
|
||||
it('should remove focus from target and text selection', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
clip.clearSelection();
|
||||
|
||||
let selectedElem = document.activeElement;
|
||||
let selectedText = window.getSelection().toString();
|
||||
|
||||
assert.equal(selectedElem, document.body);
|
||||
assert.equal(selectedText, '');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#destroy', () => {
|
||||
it('should destroy an existing fake element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah'
|
||||
});
|
||||
|
||||
clip.selectFake();
|
||||
clip.destroy();
|
||||
|
||||
assert.equal(clip.fakeElem, null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
import Clipboard from '../src/clipboard';
|
||||
import ClipboardAction from '../src/clipboard-action';
|
||||
import listen from 'good-listener';
|
||||
|
||||
describe('Clipboard', () => {
|
||||
before(() => {
|
||||
global.button = document.createElement('button');
|
||||
global.button.setAttribute('class', 'btn');
|
||||
global.button.setAttribute('data-clipboard-text', 'foo');
|
||||
document.body.appendChild(global.button);
|
||||
|
||||
global.span = document.createElement('span');
|
||||
global.span.innerHTML = 'bar';
|
||||
|
||||
global.button.appendChild(span);
|
||||
|
||||
global.event = {
|
||||
target: global.button,
|
||||
currentTarget: global.button
|
||||
};
|
||||
});
|
||||
|
||||
after(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('#resolveOptions', () => {
|
||||
before(() => {
|
||||
global.fn = () => {};
|
||||
});
|
||||
|
||||
it('should set action as a function', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
action: global.fn
|
||||
});
|
||||
|
||||
assert.equal(global.fn, clipboard.action);
|
||||
});
|
||||
|
||||
it('should set target as a function', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
target: global.fn
|
||||
});
|
||||
|
||||
assert.equal(global.fn, clipboard.target);
|
||||
});
|
||||
|
||||
it('should set text as a function', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
text: global.fn
|
||||
});
|
||||
|
||||
assert.equal(global.fn, clipboard.text);
|
||||
});
|
||||
|
||||
it('should set container as an object', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
container: document.body
|
||||
});
|
||||
|
||||
assert.equal(document.body, clipboard.container);
|
||||
});
|
||||
|
||||
it('should set container as body by default', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
assert.equal(document.body, clipboard.container);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#listenClick', () => {
|
||||
it('should add a click event listener to the passed selector', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
assert.isObject(clipboard.listener);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#onClick', () => {
|
||||
it('should create a new instance of ClipboardAction', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
assert.instanceOf(clipboard.clipboardAction, ClipboardAction);
|
||||
});
|
||||
|
||||
it('should use an event\'s currentTarget when not equal to target', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
let bubbledEvent = { target: global.span, currentTarget: global.button };
|
||||
|
||||
clipboard.onClick(bubbledEvent);
|
||||
assert.instanceOf(clipboard.clipboardAction, ClipboardAction);
|
||||
});
|
||||
|
||||
it('should throw an exception when target is invalid', done => {
|
||||
try {
|
||||
const clipboard = new Clipboard('.btn', {
|
||||
target() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
}
|
||||
catch(e) {
|
||||
assert.equal(e.message, 'Invalid "target" value, use a valid Element');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#static isSupported', () => {
|
||||
it('should return the support of the given action', () => {
|
||||
assert.equal(Clipboard.isSupported('copy'), false);
|
||||
assert.equal(Clipboard.isSupported('cut'), false);
|
||||
});
|
||||
|
||||
it('should return the support of the cut and copy actions', () => {
|
||||
assert.equal(Clipboard.isSupported(), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#destroy', () => {
|
||||
it('should destroy an existing instance of ClipboardAction', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
clipboard.destroy();
|
||||
|
||||
assert.equal(clipboard.clipboardAction, null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
const pkg = require('./package.json');
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
||||
|
||||
const production = process.env.NODE_ENV === 'production' || false;
|
||||
|
||||
const banner = `clipboard.js v${pkg.version}
|
||||
https://clipboardjs.com/
|
||||
|
||||
Licensed MIT © Zeno Rocha`;
|
||||
|
||||
module.exports = {
|
||||
entry: './src/clipboard.js',
|
||||
mode: 'production',
|
||||
output: {
|
||||
filename: production ? 'clipboard.min.js' : 'clipboard.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
library: 'ClipboardJS',
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
minimize: production,
|
||||
minimizer: [
|
||||
new UglifyJSPlugin({
|
||||
parallel: require('os').cpus().length,
|
||||
uglifyOptions: {
|
||||
ie8: false,
|
||||
keep_fnames: false,
|
||||
output: {
|
||||
beautify: false,
|
||||
comments: (node, {value, type}) => type == 'comment2' && value.startsWith('!')
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
},
|
||||
plugins: [new webpack.BannerPlugin({ banner })]
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
; https://editorconfig.org/
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
|
||||
[*.{json,yml}]
|
||||
indent_size = 2
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# Mac OS X dumps these all over the place.
|
||||
.DS_Store
|
||||
|
||||
# Ignore the SimpleTest library if it is installed to /test/.
|
||||
/test/simpletest/
|
||||
|
||||
# Ignore the /vendor/ directory for people using composer
|
||||
/vendor/
|
||||
|
||||
# If the vendor directory isn't being commited the composer.lock file should also be ignored
|
||||
composer.lock
|
||||
|
||||
# Ignore PHPUnit coverage file
|
||||
clover.xml
|
||||
|
||||
# Ignore IDE's configuration files
|
||||
.idea
|
||||
|
||||
# Ignore PHP CS Fixer cache
|
||||
.php_cs.cache
|
||||
|
|
@ -0,0 +1,769 @@
|
|||
# Changelog
|
||||
|
||||
## 7.0.2 - 2019-09-06
|
||||
* [#729](https://github.com/stripe/stripe-php/pull/729) Fix usage of `SignatureVerificationException` in PHPDoc blocks
|
||||
|
||||
## 7.0.1 - 2019-09-05
|
||||
* [#728](https://github.com/stripe/stripe-php/pull/728) Clean up Collection
|
||||
|
||||
## 7.0.0 - 2019-09-03
|
||||
Major version release. The [migration guide](https://github.com/stripe/stripe-php/wiki/Migration-guide-for-v7) contains a detailed list of backwards-incompatible changes with upgrade instructions.
|
||||
|
||||
Pull requests included in this release (cf. [#552](https://github.com/stripe/stripe-php/pull/552)) (⚠️ = breaking changes):
|
||||
* ⚠️ Drop support for PHP 5.4 ([#551](https://github.com/stripe/stripe-php/pull/551))
|
||||
* ⚠️ Drop support for PHP 5.5 ([#554](https://github.com/stripe/stripe-php/pull/554))
|
||||
* Bump dependencies ([#553](https://github.com/stripe/stripe-php/pull/553))
|
||||
* Remove `CURLFile` check ([#555](https://github.com/stripe/stripe-php/pull/555))
|
||||
* Update constant definitions for PHP >= 5.6 ([#556](https://github.com/stripe/stripe-php/pull/556))
|
||||
* ⚠️ Remove `FileUpload` alias ([#557](https://github.com/stripe/stripe-php/pull/557))
|
||||
* Remove `curl_reset` check ([#570](https://github.com/stripe/stripe-php/pull/570))
|
||||
* Use `\Stripe\<class>::class` constant instead of strings ([#643](https://github.com/stripe/stripe-php/pull/643))
|
||||
* Use `array_column` to flatten params ([#686](https://github.com/stripe/stripe-php/pull/686))
|
||||
* ⚠️ Remove deprecated methods ([#692](https://github.com/stripe/stripe-php/pull/692))
|
||||
* ⚠️ Remove `IssuerFraudRecord` ([#696](https://github.com/stripe/stripe-php/pull/696))
|
||||
* Update constructors of Stripe exception classes ([#559](https://github.com/stripe/stripe-php/pull/559))
|
||||
* Fix remaining TODOs ([#700](https://github.com/stripe/stripe-php/pull/700))
|
||||
* Use yield for autopagination ([#703](https://github.com/stripe/stripe-php/pull/703))
|
||||
* ⚠️ Rename fake magic methods and rewrite array conversion ([#704](https://github.com/stripe/stripe-php/pull/704))
|
||||
* Add `ErrorObject` to Stripe exceptions ([#705](https://github.com/stripe/stripe-php/pull/705))
|
||||
* Start using PHP CS Fixer ([#706](https://github.com/stripe/stripe-php/pull/706))
|
||||
* Update error messages for nested resource operations ([#708](https://github.com/stripe/stripe-php/pull/708))
|
||||
* Upgrade retry logic ([#707](https://github.com/stripe/stripe-php/pull/707))
|
||||
* ⚠️ `Collection` improvements / fixes ([#715](https://github.com/stripe/stripe-php/pull/715))
|
||||
* ⚠️ Modernize exceptions ([#709](https://github.com/stripe/stripe-php/pull/709))
|
||||
* Add constants for error codes ([#716](https://github.com/stripe/stripe-php/pull/716))
|
||||
* Update certificate bundle ([#717](https://github.com/stripe/stripe-php/pull/717))
|
||||
* Retry requests on a 429 that's a lock timeout ([#718](https://github.com/stripe/stripe-php/pull/718))
|
||||
* Fix `toArray()` calls ([#719](https://github.com/stripe/stripe-php/pull/719))
|
||||
* Couple of fixes for PHP 7.4 ([#725](https://github.com/stripe/stripe-php/pull/725))
|
||||
|
||||
## 6.43.1 - 2019-08-29
|
||||
* [#722](https://github.com/stripe/stripe-php/pull/722) Make `LoggerInterface::error` compatible with its PSR-3 counterpart
|
||||
* [#714](https://github.com/stripe/stripe-php/pull/714) Add `pending_setup_intent` property in `Subscription`
|
||||
* [#713](https://github.com/stripe/stripe-php/pull/713) Add typehint to `ApiResponse`
|
||||
* [#712](https://github.com/stripe/stripe-php/pull/712) Fix comment
|
||||
* [#701](https://github.com/stripe/stripe-php/pull/701) Start testing PHP 7.3
|
||||
|
||||
## 6.43.0 - 2019-08-09
|
||||
* [#694](https://github.com/stripe/stripe-php/pull/694) Add `SubscriptionItem::createUsageRecord` method
|
||||
|
||||
## 6.42.0 - 2019-08-09
|
||||
* [#688](https://github.com/stripe/stripe-php/pull/688) Remove `SubscriptionScheduleRevision`
|
||||
* Note that this is technically a breaking change, however we've chosen to release it as a minor version in light of the fact that this resource and its API methods were virtually unused.
|
||||
|
||||
## 6.41.0 - 2019-07-31
|
||||
* [#683](https://github.com/stripe/stripe-php/pull/683) Move the List Balance History API to `/v1/balance_transactions`
|
||||
|
||||
## 6.40.0 - 2019-06-27
|
||||
* [#675](https://github.com/stripe/stripe-php/pull/675) Add support for `SetupIntent` resource and APIs
|
||||
|
||||
## 6.39.2 - 2019-06-26
|
||||
* [#676](https://github.com/stripe/stripe-php/pull/676) Fix exception message in `CustomerBalanceTransaction::update()`
|
||||
|
||||
## 6.39.1 - 2019-06-25
|
||||
* [#674](https://github.com/stripe/stripe-php/pull/674) Add new constants for `collection_method` on `Invoice`
|
||||
|
||||
## 6.39.0 - 2019-06-24
|
||||
* [#673](https://github.com/stripe/stripe-php/pull/673) Enable request latency telemetry by default
|
||||
|
||||
## 6.38.0 - 2019-06-17
|
||||
* [#649](https://github.com/stripe/stripe-php/pull/649) Add support for `CustomerBalanceTransaction` resource and APIs
|
||||
|
||||
## 6.37.2 - 2019-06-17
|
||||
* [#671](https://github.com/stripe/stripe-php/pull/671) Add new PHPDoc
|
||||
* [#672](https://github.com/stripe/stripe-php/pull/672) Add constants for `submit_type` on Checkout `Session`
|
||||
|
||||
## 6.37.1 - 2019-06-14
|
||||
* [#670](https://github.com/stripe/stripe-php/pull/670) Add new PHPDoc
|
||||
|
||||
## 6.37.0 - 2019-05-23
|
||||
* [#663](https://github.com/stripe/stripe-php/pull/663) Add support for `radar.early_fraud_warning` resource
|
||||
|
||||
## 6.36.0 - 2019-05-22
|
||||
* [#661](https://github.com/stripe/stripe-php/pull/661) Add constants for new TaxId types
|
||||
* [#662](https://github.com/stripe/stripe-php/pull/662) Add constants for BalanceTransaction types
|
||||
|
||||
## 6.35.2 - 2019-05-20
|
||||
* [#655](https://github.com/stripe/stripe-php/pull/655) Add constants for payment intent statuses
|
||||
* [#659](https://github.com/stripe/stripe-php/pull/659) Fix PHPDoc for various nested Account actions
|
||||
* [#660](https://github.com/stripe/stripe-php/pull/660) Fix various PHPDoc
|
||||
|
||||
## 6.35.1 - 2019-05-20
|
||||
* [#658](https://github.com/stripe/stripe-php/pull/658) Use absolute value when checking timestamp tolerance
|
||||
|
||||
## 6.35.0 - 2019-05-14
|
||||
* [#651](https://github.com/stripe/stripe-php/pull/651) Add support for the Capability resource and APIs
|
||||
|
||||
## 6.34.6 - 2019-05-13
|
||||
* [#654](https://github.com/stripe/stripe-php/pull/654) Fix typo in definition of `Event::PAYMENT_METHOD_ATTACHED` constant
|
||||
|
||||
## 6.34.5 - 2019-05-06
|
||||
* [#647](https://github.com/stripe/stripe-php/pull/647) Set the return type to static for more operations
|
||||
|
||||
## 6.34.4 - 2019-05-06
|
||||
* [#650](https://github.com/stripe/stripe-php/pull/650) Add missing constants for Event types
|
||||
|
||||
## 6.34.3 - 2019-05-01
|
||||
* [#644](https://github.com/stripe/stripe-php/pull/644) Update return type to `static` to improve static analysis
|
||||
* [#645](https://github.com/stripe/stripe-php/pull/645) Fix constant for `payment_intent.payment_failed`
|
||||
|
||||
## 6.34.2 - 2019-04-26
|
||||
* [#642](https://github.com/stripe/stripe-php/pull/642) Fix an issue where existing idempotency keys would be overwritten when using automatic retries
|
||||
|
||||
## 6.34.1 - 2019-04-25
|
||||
* [#640](https://github.com/stripe/stripe-php/pull/640) Add missing phpdocs
|
||||
|
||||
## 6.34.0 - 2019-04-24
|
||||
* [#626](https://github.com/stripe/stripe-php/pull/626) Add support for the `TaxRate` resource and APIs
|
||||
* [#639](https://github.com/stripe/stripe-php/pull/639) Fix multiple phpdoc issues
|
||||
|
||||
## 6.33.0 - 2019-04-22
|
||||
* [#630](https://github.com/stripe/stripe-php/pull/630) Add support for the `TaxId` resource and APIs
|
||||
|
||||
## 6.32.1 - 2019-04-19
|
||||
* [#636](https://github.com/stripe/stripe-php/pull/636) Correct type of `$personId` in PHPDoc
|
||||
|
||||
## 6.32.0 - 2019-04-18
|
||||
* [#621](https://github.com/stripe/stripe-php/pull/621) Add support for `CreditNote`
|
||||
|
||||
## 6.31.5 - 2019-04-12
|
||||
* [#628](https://github.com/stripe/stripe-php/pull/628) Add constants for `person.*` event types
|
||||
* [#628](https://github.com/stripe/stripe-php/pull/628) Add missing constants for `Account` and `Person`
|
||||
|
||||
## 6.31.4 - 2019-04-05
|
||||
* [#624](https://github.com/stripe/stripe-php/pull/624) Fix encoding of nested parameters in multipart requests
|
||||
|
||||
## 6.31.3 - 2019-04-02
|
||||
* [#623](https://github.com/stripe/stripe-php/pull/623) Only use HTTP/2 with curl >= 7.60.0
|
||||
|
||||
## 6.31.2 - 2019-03-25
|
||||
* [#619](https://github.com/stripe/stripe-php/pull/619) Fix PHPDoc return types for list methods for nested resources
|
||||
|
||||
## 6.31.1 - 2019-03-22
|
||||
* [#612](https://github.com/stripe/stripe-php/pull/612) Add a lot of constants
|
||||
* [#614](https://github.com/stripe/stripe-php/pull/614) Add missing subscription status constants
|
||||
|
||||
## 6.31.0 - 2019-03-18
|
||||
* [#600](https://github.com/stripe/stripe-php/pull/600) Add support for the `PaymentMethod` resource and APIs
|
||||
* [#606](https://github.com/stripe/stripe-php/pull/606) Add support for retrieving a Checkout `Session`
|
||||
* [#611](https://github.com/stripe/stripe-php/pull/611) Add support for deleting a Terminal `Location` and `Reader`
|
||||
|
||||
## 6.30.5 - 2019-03-11
|
||||
* [#607](https://github.com/stripe/stripe-php/pull/607) Correctly handle case where a metadata key is called `metadata`
|
||||
|
||||
## 6.30.4 - 2019-02-27
|
||||
* [#602](https://github.com/stripe/stripe-php/pull/602) Add `subscription_schedule` to `Subscription` for PHPDoc.
|
||||
|
||||
## 6.30.3 - 2019-02-26
|
||||
* [#603](https://github.com/stripe/stripe-php/pull/603) Improve PHPDoc on the `Source` object to cover all types of Sources currently supported.
|
||||
|
||||
## 6.30.2 - 2019-02-25
|
||||
* [#601](https://github.com/stripe/stripe-php/pull/601) Fix PHPDoc across multiple resources and add support for new events.
|
||||
|
||||
## 6.30.1 - 2019-02-16
|
||||
* [#599](https://github.com/stripe/stripe-php/pull/599) Fix PHPDoc for `SubscriptionSchedule` and `SubscriptionScheduleRevision`
|
||||
|
||||
## 6.30.0 - 2019-02-12
|
||||
* [#590](https://github.com/stripe/stripe-php/pull/590) Add support for `SubscriptionSchedule` and `SubscriptionScheduleRevision`
|
||||
|
||||
## 6.29.3 - 2019-01-31
|
||||
* [#592](https://github.com/stripe/stripe-php/pull/592) Some more PHPDoc fixes
|
||||
|
||||
## 6.29.2 - 2019-01-31
|
||||
* [#591](https://github.com/stripe/stripe-php/pull/591) Fix PHPDoc for nested resources
|
||||
|
||||
## 6.29.1 - 2019-01-25
|
||||
* [#566](https://github.com/stripe/stripe-php/pull/566) Fix dangling message contents
|
||||
* [#586](https://github.com/stripe/stripe-php/pull/586) Don't overwrite `CURLOPT_HTTP_VERSION` option
|
||||
|
||||
## 6.29.0 - 2019-01-23
|
||||
* [#579](https://github.com/stripe/stripe-php/pull/579) Rename `CheckoutSession` to `Session` and move it under the `Checkout` namespace. This is a breaking change, but we've reached out to affected merchants and all new merchants would use the new approach.
|
||||
|
||||
## 6.28.1 - 2019-01-21
|
||||
* [#580](https://github.com/stripe/stripe-php/pull/580) Properly serialize `individual` on `Account` objects
|
||||
|
||||
## 6.28.0 - 2019-01-03
|
||||
* [#576](https://github.com/stripe/stripe-php/pull/576) Add support for iterating directly over `Collection` instances
|
||||
|
||||
## 6.27.0 - 2018-12-21
|
||||
* [#571](https://github.com/stripe/stripe-php/pull/571) Add support for the `CheckoutSession` resource
|
||||
|
||||
## 6.26.0 - 2018-12-11
|
||||
* [#568](https://github.com/stripe/stripe-php/pull/568) Enable persistent connections
|
||||
|
||||
## 6.25.0 - 2018-12-10
|
||||
* [#567](https://github.com/stripe/stripe-php/pull/567) Add support for account links
|
||||
|
||||
## 6.24.0 - 2018-11-28
|
||||
* [#562](https://github.com/stripe/stripe-php/pull/562) Add support for the Review resource
|
||||
* [#564](https://github.com/stripe/stripe-php/pull/564) Add event name constants for subscription schedule aborted/expiring
|
||||
|
||||
## 6.23.0 - 2018-11-27
|
||||
* [#542](https://github.com/stripe/stripe-php/pull/542) Add support for `ValueList` and `ValueListItem` for Radar
|
||||
|
||||
## 6.22.1 - 2018-11-20
|
||||
* [#561](https://github.com/stripe/stripe-php/pull/561) Add cast and some docs to telemetry introduced in 6.22.0/549
|
||||
|
||||
## 6.22.0 - 2018-11-15
|
||||
* [#549](https://github.com/stripe/stripe-php/pull/549) Add support for client telemetry
|
||||
|
||||
## 6.21.1 - 2018-11-12
|
||||
* [#548](https://github.com/stripe/stripe-php/pull/548) Don't mutate `Exception` class properties from `OAuthBase` error
|
||||
|
||||
## 6.21.0 - 2018-11-08
|
||||
* [#537](https://github.com/stripe/stripe-php/pull/537) Add new API endpoints for the `Invoice` resource.
|
||||
|
||||
## 6.20.1 - 2018-11-07
|
||||
* [#546](https://github.com/stripe/stripe-php/pull/546) Drop files from the Composer package that aren't needed in the release
|
||||
|
||||
## 6.20.0 - 2018-10-30
|
||||
* [#536](https://github.com/stripe/stripe-php/pull/536) Add support for the `Person` resource
|
||||
* [#541](https://github.com/stripe/stripe-php/pull/541) Add support for the `WebhookEndpoint` resource
|
||||
|
||||
## 6.19.5 - 2018-10-17
|
||||
* [#539](https://github.com/stripe/stripe-php/pull/539) Fix methods on `\Stripe\PaymentIntent` to properly pass arguments to the API.
|
||||
|
||||
## 6.19.4 - 2018-10-11
|
||||
* [#534](https://github.com/stripe/stripe-php/pull/534) Fix PSR-4 autoloading for `\Stripe\FileUpload` class alias
|
||||
|
||||
## 6.19.3 - 2018-10-09
|
||||
* [#530](https://github.com/stripe/stripe-php/pull/530) Add constants for `flow` (`FLOW_*`), `status` (`STATUS_*`) and `usage` (`USAGE_*`) on `\Stripe\Source`
|
||||
|
||||
## 6.19.2 - 2018-10-08
|
||||
* [#531](https://github.com/stripe/stripe-php/pull/531) Store HTTP response headers in case-insensitive array
|
||||
|
||||
## 6.19.1 - 2018-09-25
|
||||
* [#526](https://github.com/stripe/stripe-php/pull/526) Ignore null values in request parameters
|
||||
|
||||
## 6.19.0 - 2018-09-24
|
||||
* [#523](https://github.com/stripe/stripe-php/pull/523) Add support for Stripe Terminal
|
||||
|
||||
## 6.18.0 - 2018-09-24
|
||||
* [#520](https://github.com/stripe/stripe-php/pull/520) Rename `\Stripe\FileUpload` to `\Stripe\File`
|
||||
|
||||
## 6.17.2 - 2018-09-18
|
||||
* [#522](https://github.com/stripe/stripe-php/pull/522) Fix warning when adding a new additional owner to an existing array
|
||||
|
||||
## 6.17.1 - 2018-09-14
|
||||
* [#517](https://github.com/stripe/stripe-php/pull/517) Integer-index encode all sequential arrays
|
||||
|
||||
## 6.17.0 - 2018-09-05
|
||||
* [#514](https://github.com/stripe/stripe-php/pull/514) Add support for reporting resources
|
||||
|
||||
## 6.16.0 - 2018-08-23
|
||||
* [#509](https://github.com/stripe/stripe-php/pull/509) Add support for usage record summaries
|
||||
|
||||
## 6.15.0 - 2018-08-03
|
||||
* [#504](https://github.com/stripe/stripe-php/pull/504) Add cancel support for topups
|
||||
|
||||
## 6.14.0 - 2018-08-02
|
||||
* [#505](https://github.com/stripe/stripe-php/pull/505) Add support for file links
|
||||
|
||||
## 6.13.0 - 2018-07-31
|
||||
* [#502](https://github.com/stripe/stripe-php/pull/502) Add `isDeleted()` method to `\Stripe\StripeObject`
|
||||
|
||||
## 6.12.0 - 2018-07-28
|
||||
* [#501](https://github.com/stripe/stripe-php/pull/501) Add support for scheduled query runs (`\Stripe\Sigma\ScheduledQueryRun`) for Sigma
|
||||
|
||||
## 6.11.0 - 2018-07-26
|
||||
* [#500](https://github.com/stripe/stripe-php/pull/500) Add support for Stripe Issuing
|
||||
|
||||
## 6.10.4 - 2018-07-19
|
||||
* [#498](https://github.com/stripe/stripe-php/pull/498) Internal improvements to the `\Stripe\ApiResource.classUrl()` method
|
||||
|
||||
## 6.10.3 - 2018-07-16
|
||||
* [#497](https://github.com/stripe/stripe-php/pull/497) Use HTTP/2 only for HTTPS requests
|
||||
|
||||
## 6.10.2 - 2018-07-11
|
||||
* [#494](https://github.com/stripe/stripe-php/pull/494) Enable HTTP/2 support
|
||||
|
||||
## 6.10.1 - 2018-07-10
|
||||
* [#493](https://github.com/stripe/stripe-php/pull/493) Add PHPDoc for `auto_advance` on `\Stripe\Invoice`
|
||||
|
||||
## 6.10.0 - 2018-06-28
|
||||
* [#488](https://github.com/stripe/stripe-php/pull/488) Add support for `$appPartnerId` to `Stripe::setAppInfo()`
|
||||
|
||||
## 6.9.0 - 2018-06-28
|
||||
* [#487](https://github.com/stripe/stripe-php/pull/487) Add support for payment intents
|
||||
|
||||
## 6.8.2 - 2018-06-24
|
||||
* [#486](https://github.com/stripe/stripe-php/pull/486) Make `Account.deauthorize()` return the `StripeObject` from the API
|
||||
|
||||
## 6.8.1 - 2018-06-13
|
||||
* [#472](https://github.com/stripe/stripe-php/pull/472) Added phpDoc for `ApiRequestor` and others, especially regarding thrown errors
|
||||
|
||||
## 6.8.0 - 2018-06-13
|
||||
* [#481](https://github.com/stripe/stripe-php/pull/481) Add new `\Stripe\Discount` and `\Stripe\OrderItem` classes, add more PHPDoc describing object attributes
|
||||
|
||||
## 6.7.4 - 2018-05-29
|
||||
* [#480](https://github.com/stripe/stripe-php/pull/480) PHPDoc changes for API version 2018-05-21 and the addition of the new `CHARGE_EXPIRED` event type
|
||||
|
||||
## 6.7.3 - 2018-05-28
|
||||
* [#479](https://github.com/stripe/stripe-php/pull/479) Fix unnecessary traits on `\Stripe\InvoiceLineItem`
|
||||
|
||||
## 6.7.2 - 2018-05-28
|
||||
* [#471](https://github.com/stripe/stripe-php/pull/471) Add `OBJECT_NAME` constant to all API resource classes, add `\Stripe\InvoiceLineItem` class
|
||||
|
||||
## 6.7.1 - 2018-05-13
|
||||
* [#468](https://github.com/stripe/stripe-php/pull/468) Update fields in PHP docs for accuracy
|
||||
|
||||
## 6.7.0 - 2018-05-09
|
||||
* [#466](https://github.com/stripe/stripe-php/pull/466) Add support for issuer fraud records
|
||||
|
||||
## 6.6.0 - 2018-04-11
|
||||
* [#460](https://github.com/stripe/stripe-php/pull/460) Add support for flexible billing primitives
|
||||
|
||||
## 6.5.0 - 2018-04-05
|
||||
* [#461](https://github.com/stripe/stripe-php/pull/461) Don't zero keys on non-`metadata` subobjects
|
||||
|
||||
## 6.4.2 - 2018-03-17
|
||||
* [#458](https://github.com/stripe/stripe-php/pull/458) Add PHPDoc for `account` on `\Stripe\Event`
|
||||
|
||||
## 6.4.1 - 2018-03-02
|
||||
* [#455](https://github.com/stripe/stripe-php/pull/455) Fix namespaces in PHPDoc
|
||||
* [#456](https://github.com/stripe/stripe-php/pull/456) Fix namespaces for some exceptions
|
||||
|
||||
## 6.4.0 - 2018-02-28
|
||||
* [#453](https://github.com/stripe/stripe-php/pull/453) Add constants for `reason` (`REASON_*`) and `status` (`STATUS_*`) on `\Stripe\Dispute`
|
||||
|
||||
## 6.3.2 - 2018-02-27
|
||||
* [#452](https://github.com/stripe/stripe-php/pull/452) Add PHPDoc for `amount_paid` and `amount_remaining` on `\Stripe\Invoice`
|
||||
|
||||
## 6.3.1 - 2018-02-26
|
||||
* [#443](https://github.com/stripe/stripe-php/pull/443) Add event types as constants to `\Stripe\Event` class
|
||||
|
||||
## 6.3.0 - 2018-02-23
|
||||
* [#450](https://github.com/stripe/stripe-php/pull/450) Add support for `code` attribute on all Stripe exceptions
|
||||
|
||||
## 6.2.0 - 2018-02-21
|
||||
* [#440](https://github.com/stripe/stripe-php/pull/440) Add support for topups
|
||||
* [#442](https://github.com/stripe/stripe-php/pull/442) Fix PHPDoc for `\Stripe\Error\SignatureVerification`
|
||||
|
||||
## 6.1.0 - 2018-02-12
|
||||
* [#435](https://github.com/stripe/stripe-php/pull/435) Fix header persistence on `Collection` objects
|
||||
* [#436](https://github.com/stripe/stripe-php/pull/436) Introduce new `Idempotency` error class
|
||||
|
||||
## 6.0.0 - 2018-02-07
|
||||
Major version release. List of backwards incompatible changes to watch out for:
|
||||
+ The minimum PHP version is now 5.4.0. If you're using PHP 5.3 or older, consider upgrading to a more recent version.
|
||||
* `\Stripe\AttachedObject` no longer exists. Attributes that used to be instances of `\Stripe\AttachedObject` (such as `metadata`) are now instances of `\Stripe\StripeObject`.
|
||||
+ Attributes that used to be PHP arrays (such as `legal_entity->additional_owners` on `\Stripe\Account` instances) are now instances of `\Stripe\StripeObject`, except when they are empty. `\Stripe\StripeObject` has array semantics so this should not be an issue unless you are actively checking types.
|
||||
* `\Stripe\Collection` now derives from `\Stripe\StripeObject` rather than from `\Stripe\ApiResource`.
|
||||
|
||||
Pull requests included in this release:
|
||||
* [#410](https://github.com/stripe/stripe-php/pull/410) Drop support for PHP 5.3
|
||||
* [#411](https://github.com/stripe/stripe-php/pull/411) Use traits for common API operations
|
||||
* [#414](https://github.com/stripe/stripe-php/pull/414) Use short array syntax
|
||||
* [#404](https://github.com/stripe/stripe-php/pull/404) Fix serialization logic
|
||||
* [#417](https://github.com/stripe/stripe-php/pull/417) Remove `ExternalAccount` class
|
||||
* [#418](https://github.com/stripe/stripe-php/pull/418) Increase test coverage
|
||||
* [#421](https://github.com/stripe/stripe-php/pull/421) Update CA bundle and add script for future updates
|
||||
* [#422](https://github.com/stripe/stripe-php/pull/422) Use vendored CA bundle for all requests
|
||||
* [#428](https://github.com/stripe/stripe-php/pull/428) Support for automatic request retries
|
||||
|
||||
## 5.9.2 - 2018-02-07
|
||||
* [#431](https://github.com/stripe/stripe-php/pull/431) Update PHPDoc @property tags for latest API version
|
||||
|
||||
## 5.9.1 - 2018-02-06
|
||||
* [#427](https://github.com/stripe/stripe-php/pull/427) Add and update PHPDoc @property tags on all API resources
|
||||
|
||||
## 5.9.0 - 2018-01-17
|
||||
* [#421](https://github.com/stripe/stripe-php/pull/421) Updated bundled CA certificates
|
||||
* [#423](https://github.com/stripe/stripe-php/pull/423) Escape unsanitized input in OAuth example
|
||||
|
||||
## 5.8.0 - 2017-12-20
|
||||
* [#403](https://github.com/stripe/stripe-php/pull/403) Add `__debugInfo()` magic method to `StripeObject`
|
||||
|
||||
## 5.7.0 - 2017-11-28
|
||||
* [#390](https://github.com/stripe/stripe-php/pull/390) Remove some unsupported API methods
|
||||
* [#391](https://github.com/stripe/stripe-php/pull/391) Alphabetize the list of API resources in `Util::convertToStripeObject()` and add missing resources
|
||||
* [#393](https://github.com/stripe/stripe-php/pull/393) Fix expiry date update for card sources
|
||||
|
||||
## 5.6.0 - 2017-10-31
|
||||
* [#386](https://github.com/stripe/stripe-php/pull/386) Support for exchange rates APIs
|
||||
|
||||
## 5.5.1 - 2017-10-30
|
||||
* [#387](https://github.com/stripe/stripe-php/pull/387) Allow `personal_address_kana` and `personal_address_kanji` to be updated on an account
|
||||
|
||||
## 5.5.0 - 2017-10-27
|
||||
* [#385](https://github.com/stripe/stripe-php/pull/385) Support for listing source transactions
|
||||
|
||||
## 5.4.0 - 2017-10-24
|
||||
* [#383](https://github.com/stripe/stripe-php/pull/383) Add static methods to manipulate resources from parent
|
||||
* `Account` gains methods for external accounts and login links (e.g. `createExternalAccount`, `createLoginLink`)
|
||||
* `ApplicationFee` gains methods for refunds
|
||||
* `Customer` gains methods for sources
|
||||
* `Transfer` gains methods for reversals
|
||||
|
||||
## 5.3.0 - 2017-10-11
|
||||
* [#378](https://github.com/stripe/stripe-php/pull/378) Rename source `delete` to `detach` (and deprecate the former)
|
||||
|
||||
## 5.2.3 - 2017-09-27
|
||||
* Add PHPDoc for `Card`
|
||||
|
||||
## 5.2.2 - 2017-09-20
|
||||
* Fix deserialization mapping of `FileUpload` objects
|
||||
|
||||
## 5.2.1 - 2017-09-14
|
||||
* Serialized `shipping` nested attribute
|
||||
|
||||
## 5.2.0 - 2017-08-29
|
||||
* Add support for `InvalidClient` OAuth error
|
||||
|
||||
## 5.1.3 - 2017-08-14
|
||||
* Allow `address_kana` and `address_kanji` to be updated for custom accounts
|
||||
|
||||
## 5.1.2 - 2017-08-01
|
||||
* Fix documented return type of `autoPagingIterator()` (was missing namespace)
|
||||
|
||||
## 5.1.1 - 2017-07-03
|
||||
* Fix order returns to use the right URL `/v1/order_returns`
|
||||
|
||||
## 5.1.0 - 2017-06-30
|
||||
* Add support for OAuth
|
||||
|
||||
## 5.0.0 - 2017-06-27
|
||||
* `pay` on invoice now takes params as well as opts
|
||||
|
||||
## 4.13.0 - 2017-06-19
|
||||
* Add support for ephemeral keys
|
||||
|
||||
## 4.12.0 - 2017-06-05
|
||||
* Clients can implement `getUserAgentInfo()` to add additional user agent information
|
||||
|
||||
## 4.11.0 - 2017-06-05
|
||||
* Implement `Countable` for `AttachedObject` (`metadata` and `additional_owners`)
|
||||
|
||||
## 4.10.0 - 2017-05-25
|
||||
* Add support for login links
|
||||
|
||||
## 4.9.1 - 2017-05-10
|
||||
* Fix docs to include arrays on `$id` parameter for retrieve methods
|
||||
|
||||
## 4.9.0 - 2017-04-28
|
||||
* Support for checking webhook signatures
|
||||
|
||||
## 4.8.1 - 2017-04-24
|
||||
* Allow nested field `payout_schedule` to be updated
|
||||
|
||||
## 4.8.0 - 2017-04-20
|
||||
* Add `\Stripe\Stripe::setLogger()` to support an external PSR-3 compatible logger
|
||||
|
||||
## 4.7.0 - 2017-04-10
|
||||
* Add support for payouts and recipient transfers
|
||||
|
||||
## 4.6.0 - 2017-04-06
|
||||
* Please see 4.7.0 instead (no-op release)
|
||||
|
||||
## 4.5.1 - 2017-03-22
|
||||
* Remove hard dependency on cURL
|
||||
|
||||
## 4.5.0 - 2017-03-20
|
||||
* Support for detaching sources from customers
|
||||
|
||||
## 4.4.2 - 2017-02-27
|
||||
* Correct handling of `owner` parameter when updating sources
|
||||
|
||||
## 4.4.1 - 2017-02-24
|
||||
* Correct the error check on a bad JSON decoding
|
||||
|
||||
## 4.4.0 - 2017-01-18
|
||||
* Add support for updating sources
|
||||
|
||||
## 4.3.0 - 2016-11-30
|
||||
* Add support for verifying sources
|
||||
|
||||
## 4.2.0 - 2016-11-21
|
||||
* Add retrieve method for 3-D Secure resources
|
||||
|
||||
## 4.1.1 - 2016-10-21
|
||||
* Add docblock with model properties for `Plan`
|
||||
|
||||
## 4.1.0 - 2016-10-18
|
||||
* Support for 403 status codes (permission denied)
|
||||
|
||||
## 4.0.1 - 2016-10-17
|
||||
* Fix transfer reversal materialization
|
||||
* Fixes for some property definitions in docblocks
|
||||
|
||||
## 4.0.0 - 2016-09-28
|
||||
* Support for subscription items
|
||||
* Drop attempt to force TLS 1.2: please note that this could be breaking if you're using old OS distributions or packages and upgraded recently (so please make sure to test your integration!)
|
||||
|
||||
## 3.23.0 - 2016-09-15
|
||||
* Add support for Apple Pay domains
|
||||
|
||||
## 3.22.0 - 2016-09-13
|
||||
* Add `Stripe::setAppInfo` to allow plugins to register user agent information
|
||||
|
||||
## 3.21.0 - 2016-08-25
|
||||
* Add `Source` model for generic payment sources
|
||||
|
||||
## 3.20.0 - 2016-08-08
|
||||
* Add `getDeclineCode` to card errors
|
||||
|
||||
## 3.19.0 - 2016-07-29
|
||||
* Opt requests directly into TLS 1.2 where OpenSSL >= 1.0.1 (see #277 for context)
|
||||
|
||||
## 3.18.0 - 2016-07-28
|
||||
* Add new `STATUS_` constants for subscriptions
|
||||
|
||||
## 3.17.1 - 2016-07-28
|
||||
* Fix auto-paging iterator so that it plays nicely with `iterator_to_array`
|
||||
|
||||
## 3.17.0 - 2016-07-14
|
||||
* Add field annotations to model classes for better editor hinting
|
||||
|
||||
## 3.16.0 - 2016-07-12
|
||||
* Add `ThreeDSecure` model for 3-D secure payments
|
||||
|
||||
## 3.15.0 - 2016-06-29
|
||||
* Add static `update` method to all resources that can be changed.
|
||||
|
||||
## 3.14.3 - 2016-06-20
|
||||
* Make sure that cURL never sends `Expects: 100-continue`, even on large request bodies
|
||||
|
||||
## 3.14.2 - 2016-06-03
|
||||
* Add `inventory` under `SKU` to list of keys that have nested data and can be updated
|
||||
|
||||
## 3.14.1 - 2016-05-27
|
||||
* Fix some inconsistencies in PHPDoc
|
||||
|
||||
## 3.14.0 - 2016-05-25
|
||||
* Add support for returning Relay orders
|
||||
|
||||
## 3.13.0 - 2016-05-04
|
||||
* Add `list`, `create`, `update`, `retrieve`, and `delete` methods to the Subscription class
|
||||
|
||||
## 3.12.1 - 2016-04-07
|
||||
* Additional check on value arrays for some extra safety
|
||||
|
||||
## 3.12.0 - 2016-03-31
|
||||
* Fix bug `refreshFrom` on `StripeObject` would not take an `$opts` array
|
||||
* Fix bug where `$opts` not passed to parent `save` method in `Account`
|
||||
* Fix bug where non-existent variable was referenced in `reverse` in `Transfer`
|
||||
* Update CA cert bundle for compatibility with OpenSSL versions below 1.0.1
|
||||
|
||||
## 3.11.0 - 2016-03-22
|
||||
* Allow `CurlClient` to be initialized with default `CURLOPT_*` options
|
||||
|
||||
## 3.10.1 - 2016-03-22
|
||||
* Fix bug where request params and options were ignored in `ApplicationFee`'s `refund.`
|
||||
|
||||
## 3.10.0 - 2016-03-15
|
||||
* Add `reject` on `Account` to support the new API feature
|
||||
|
||||
## 3.9.2 - 2016-03-04
|
||||
* Fix error when an object's metadata is set more than once
|
||||
|
||||
## 3.9.1 - 2016-02-24
|
||||
* Fix encoding behavior of nested arrays for requests (see #227)
|
||||
|
||||
## 3.9.0 - 2016-02-09
|
||||
* Add automatic pagination mechanism with `autoPagingIterator()`
|
||||
* Allow global account ID to be set with `Stripe::setAccountId()`
|
||||
|
||||
## 3.8.0 - 2016-02-08
|
||||
* Add `CountrySpec` model for looking up country payment information
|
||||
|
||||
## 3.7.1 - 2016-02-01
|
||||
* Update bundled CA certs
|
||||
|
||||
## 3.7.0 - 2016-01-27
|
||||
* Support deleting Relay products and SKUs
|
||||
|
||||
## 3.6.0 - 2016-01-05
|
||||
* Allow configuration of HTTP client timeouts
|
||||
|
||||
## 3.5.0 - 2015-12-01
|
||||
* Add a verification routine for external accounts
|
||||
|
||||
## 3.4.0 - 2015-09-14
|
||||
* Products, SKUs, and Orders -- https://stripe.com/relay
|
||||
|
||||
## 3.3.0 - 2015-09-11
|
||||
* Add support for 429 Rate Limit response
|
||||
|
||||
## 3.2.0 - 2015-08-17
|
||||
* Add refund listing and retrieval without an associated charge
|
||||
|
||||
## 3.1.0 - 2015-08-03
|
||||
* Add dispute listing and retrieval
|
||||
* Add support for manage account deletion
|
||||
|
||||
## 3.0.0 - 2015-07-28
|
||||
* Rename `\Stripe\Object` to `\Stripe\StripeObject` (PHP 7 compatibility)
|
||||
* Rename `getCode` and `getParam` in exceptions to `getStripeCode` and `getStripeParam`
|
||||
* Add support for calling `json_encode` on Stripe objects in PHP 5.4+
|
||||
* Start supporting/testing PHP 7
|
||||
|
||||
## 2.3.0 - 2015-07-06
|
||||
* Add request ID to all Stripe exceptions
|
||||
|
||||
## 2.2.0 - 2015-06-01
|
||||
* Add support for Alipay accounts as sources
|
||||
* Add support for bank accounts as sources (private beta)
|
||||
* Add support for bank accounts and cards as external_accounts on Account objects
|
||||
|
||||
## 2.1.4 - 2015-05-13
|
||||
* Fix CA certificate file path (thanks @lphilps & @matthewarkin)
|
||||
|
||||
## 2.1.3 - 2015-05-12
|
||||
* Fix to account updating to permit `tos_acceptance` and `personal_address` to be set properly
|
||||
* Fix to Transfer reversal creation (thanks @neatness!)
|
||||
* Network requests are now done through a swappable class for easier mocking
|
||||
|
||||
## 2.1.2 - 2015-04-10
|
||||
* Remove SSL cert revokation checking (all pre-Heartbleed certs have expired)
|
||||
* Bug fixes to account updating
|
||||
|
||||
## 2.1.1 - 2015-02-27
|
||||
* Support transfer reversals
|
||||
|
||||
## 2.1.0 - 2015-02-19
|
||||
* Support new API version (2015-02-18)
|
||||
* Added Bitcoin Receiever update and delete actions
|
||||
* Edited tests to prefer "source" over "card" as per new API version
|
||||
|
||||
## 2.0.1 - 2015-02-16
|
||||
* Fix to fetching endpoints that use a non-default baseUrl (`FileUpload`)
|
||||
|
||||
## 2.0.0 - 2015-02-14
|
||||
* Bumped minimum version to 5.3.3
|
||||
* Switched to Stripe namespace instead of Stripe_ class name prefiexes (thanks @chadicus!)
|
||||
* Switched tests to PHPUnit (thanks @chadicus!)
|
||||
* Switched style guide to PSR2 (thanks @chadicus!)
|
||||
* Added $opts hash to the end of most methods: this permits passing 'idempotency_key', 'stripe_account', or 'stripe_version'. The last 2 will persist across multiple object loads.
|
||||
* Added support for retrieving Account by ID
|
||||
|
||||
## 1.18.0 - 2015-01-21
|
||||
* Support making bitcoin charges through BitcoinReceiver source object
|
||||
|
||||
## 1.17.5 - 2014-12-23
|
||||
* Adding support for creating file uploads.
|
||||
|
||||
## 1.17.4 - 2014-12-15
|
||||
* Saving objects fetched with a custom key now works (thanks @JustinHook & @jpasilan)
|
||||
* Added methods for reporting charges as safe or fraudulent and for specifying the reason for refunds
|
||||
|
||||
## 1.17.3 - 2014-11-06
|
||||
* Better handling of HHVM support for SSL certificate blacklist checking.
|
||||
|
||||
## 1.17.2 - 2014-09-23
|
||||
* Coupons now are backed by a `Stripe_Coupon` instead of `Stripe_Object`, and support updating metadata
|
||||
* Running operations (`create`, `retrieve`, `all`) on upcoming invoice items now works
|
||||
|
||||
## 1.17.1 - 2014-07-31
|
||||
* Requests now send Content-Type header
|
||||
|
||||
## 1.17.0 - 2014-07-29
|
||||
* Application Fee refunds now a list instead of array
|
||||
* HHVM now works
|
||||
* Small bug fixes (thanks @bencromwell & @fastest963)
|
||||
* `__toString` now returns the name of the object in addition to its JSON representation
|
||||
|
||||
## 1.16.0 - 2014-06-17
|
||||
* Add metadata for refunds and disputes
|
||||
|
||||
## 1.15.0 - 2014-05-28
|
||||
* Support canceling transfers
|
||||
|
||||
## 1.14.1 - 2014-05-21
|
||||
* Support cards for recipients.
|
||||
|
||||
## 1.13.1 - 2014-05-15
|
||||
* Fix bug in account resource where `id` wasn't in the result
|
||||
|
||||
## 1.13.0 - 2014-04-10
|
||||
* Add support for certificate blacklisting
|
||||
* Update ca bundle
|
||||
* Drop support for HHVM (Temporarily)
|
||||
|
||||
## 1.12.0 - 2014-04-01
|
||||
* Add Stripe_RateLimitError for catching rate limit errors.
|
||||
* Update to Zend coding style (thanks, @jpiasetz)
|
||||
|
||||
## 1.11.0 - 2014-01-29
|
||||
* Add support for multiple subscriptions per customer
|
||||
|
||||
## 1.10.1 - 2013-12-02
|
||||
* Add new ApplicationFee
|
||||
|
||||
## 1.9.1 - 2013-11-08
|
||||
* Fix a bug where a null nestable object causes warnings to fire.
|
||||
|
||||
## 1.9.0 - 2013-10-16
|
||||
* Add support for metadata API.
|
||||
|
||||
## 1.8.4 - 2013-09-18
|
||||
* Add support for closing disputes.
|
||||
|
||||
## 1.8.3 - 2013-08-13
|
||||
* Add new Balance and BalanceTransaction
|
||||
|
||||
## 1.8.2 - 2013-08-12
|
||||
* Add support for unsetting attributes by updating to NULL. Setting properties to a blank string is now an error.
|
||||
|
||||
## 1.8.1 - 2013-07-12
|
||||
* Add support for multiple cards API (Stripe API version 2013-07-12: https://stripe.com/docs/upgrades#2013-07-05)
|
||||
|
||||
## 1.8.0 - 2013-04-11
|
||||
* Allow Transfers to be creatable
|
||||
* Add new Recipient resource
|
||||
|
||||
## 1.7.15 - 2013-02-21
|
||||
* Add 'id' to the list of permanent object attributes
|
||||
|
||||
## 1.7.14 - 2013-02-20
|
||||
|
||||
* Don't re-encode strings that are already encoded in UTF-8. If you were previously using plan or coupon objects with UTF-8 IDs, they may have been treated as ISO-8859-1 (Latin-1) and encoded to UTF-8 a 2nd time. You may now need to pass the IDs to utf8_encode before passing them to Stripe_Plan::retrieve or Stripe_Coupon::retrieve.
|
||||
* Ensure that all input is encoded in UTF-8 before submitting it to Stripe's servers. (github issue #27)
|
||||
|
||||
## 1.7.13 - 2013-02-01
|
||||
* Add support for passing options when retrieving Stripe objects e.g., Stripe_Charge::retrieve(array("id"=>"foo", "expand" => array("customer"))); Stripe_Charge::retrieve("foo") will continue to work
|
||||
|
||||
## 1.7.12 - 2013-01-15
|
||||
* Add support for setting a Stripe API version override
|
||||
|
||||
## 1.7.11 - 2012-12-30
|
||||
* Version bump to cleanup constants and such (fix issue #26)
|
||||
|
||||
## 1.7.10 - 2012-11-08
|
||||
* Add support for updating charge disputes.
|
||||
* Fix bug preventing retrieval of null attributes
|
||||
|
||||
## 1.7.9 - 2012-11-08
|
||||
* Fix usage under autoloaders such as the one generated by composer (fix issue #22)
|
||||
|
||||
## 1.7.8 - 2012-10-30
|
||||
* Add support for creating invoices.
|
||||
* Add support for new invoice lines return format
|
||||
* Add support for new list objects
|
||||
|
||||
## 1.7.7 - 2012-09-14
|
||||
* Get all of the various version numbers in the repo in sync (no other changes)
|
||||
|
||||
## 1.7.6 - 2012-08-31
|
||||
* Add update and pay methods to Invoice resource
|
||||
|
||||
## 1.7.5 - 2012-08-23
|
||||
* Change internal function names so that Stripe_SingletonApiRequest is E_STRICT-clean (github issue #16)
|
||||
|
||||
## 1.7.4 - 2012-08-21
|
||||
* Bugfix so that Stripe objects (e.g. Customer, Charge objects) used in API calls are transparently converted to their object IDs
|
||||
|
||||
## 1.7.3 - 2012-08-15
|
||||
* Add new Account resource
|
||||
|
||||
## 1.7.2 - 2012-06-26
|
||||
* Make clearer that you should be including lib/Stripe.php, not test/Stripe.php (github issue #14)
|
||||
|
||||
## 1.7.1 - 2012-05-24
|
||||
* Add missing argument to Stripe_InvalidRequestError constructor in Stripe_ApiResource::instanceUrl. Fixes a warning when Stripe_ApiResource::instanceUrl is called on a resource with no ID (fix issue #12)
|
||||
|
||||
## 1.7.0 - 2012-05-17
|
||||
* Support Composer and Packagist (github issue #9)
|
||||
* Add new deleteDiscount method to Stripe_Customer
|
||||
* Add new Transfer resource
|
||||
* Switch from using HTTP Basic auth to Bearer auth. (Note: Stripe will support Basic auth for the indefinite future, but recommends Bearer auth when possible going forward)
|
||||
* Numerous test suite improvements
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License
|
||||
|
||||
Copyright (c) 2010-2019 Stripe, Inc. (https://stripe.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
# Stripe PHP bindings
|
||||
|
||||
[](https://travis-ci.org/stripe/stripe-php)
|
||||
[](https://packagist.org/packages/stripe/stripe-php)
|
||||
[](https://packagist.org/packages/stripe/stripe-php)
|
||||
[](https://packagist.org/packages/stripe/stripe-php)
|
||||
[](https://coveralls.io/r/stripe/stripe-php?branch=master)
|
||||
|
||||
The Stripe PHP library provides convenient access to the Stripe API from
|
||||
applications written in the PHP language. It includes a pre-defined set of
|
||||
classes for API resources that initialize themselves dynamically from API
|
||||
responses which makes it compatible with a wide range of versions of the Stripe
|
||||
API.
|
||||
|
||||
## Requirements
|
||||
|
||||
PHP 5.6.0 and later.
|
||||
|
||||
## Composer
|
||||
|
||||
You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:
|
||||
|
||||
```bash
|
||||
composer require stripe/stripe-php
|
||||
```
|
||||
|
||||
To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
|
||||
|
||||
```php
|
||||
require_once('vendor/autoload.php');
|
||||
```
|
||||
|
||||
## Manual Installation
|
||||
|
||||
If you do not wish to use Composer, you can download the [latest release](https://github.com/stripe/stripe-php/releases). Then, to use the bindings, include the `init.php` file.
|
||||
|
||||
```php
|
||||
require_once('/path/to/stripe-php/init.php');
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
The bindings require the following extensions in order to work properly:
|
||||
|
||||
- [`curl`](https://secure.php.net/manual/en/book.curl.php), although you can use your own non-cURL client if you prefer
|
||||
- [`json`](https://secure.php.net/manual/en/book.json.php)
|
||||
- [`mbstring`](https://secure.php.net/manual/en/book.mbstring.php) (Multibyte String)
|
||||
|
||||
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Simple usage looks like:
|
||||
|
||||
```php
|
||||
\Stripe\Stripe::setApiKey('sk_test_BQokikJOvBiI2HlWgH4olfQ2');
|
||||
$charge = \Stripe\Charge::create(['amount' => 2000, 'currency' => 'usd', 'source' => 'tok_189fqt2eZvKYlo2CTGBeg6Uq']);
|
||||
echo $charge;
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
See the [PHP API docs](https://stripe.com/docs/api/php#intro).
|
||||
|
||||
## Legacy Version Support
|
||||
|
||||
### PHP 5.4 & 5.5
|
||||
|
||||
If you are using PHP 5.4 or 5.5, you can download v6.21.1 ([zip](https://github.com/stripe/stripe-php/archive/v6.21.1.zip), [tar.gz](https://github.com/stripe/stripe-php/archive/v5.9.2.tar.gz)) from our [releases page](https://github.com/stripe/stripe-php/releases). This version will continue to work with new versions of the Stripe API for all common uses.
|
||||
|
||||
### PHP 5.3
|
||||
|
||||
If you are using PHP 5.3, you can download v5.9.2 ([zip](https://github.com/stripe/stripe-php/archive/v5.9.2.zip), [tar.gz](https://github.com/stripe/stripe-php/archive/v5.9.2.tar.gz)) from our [releases page](https://github.com/stripe/stripe-php/releases). This version will continue to work with new versions of the Stripe API for all common uses.
|
||||
|
||||
### PHP 5.2
|
||||
|
||||
If you are using PHP 5.2, you can download v1.18.0 ([zip](https://github.com/stripe/stripe-php/archive/v1.18.0.zip), [tar.gz](https://github.com/stripe/stripe-php/archive/v1.18.0.tar.gz)) from our [releases page](https://github.com/stripe/stripe-php/releases). This version will continue to work with new versions of the Stripe API for all common uses.
|
||||
|
||||
This legacy version may be included via `require_once("/path/to/stripe-php/lib/Stripe.php");`, and used like:
|
||||
|
||||
```php
|
||||
Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
|
||||
$charge = Stripe_Charge::create(array('source' => 'tok_XXXXXXXX', 'amount' => 2000, 'currency' => 'usd'));
|
||||
echo $charge;
|
||||
```
|
||||
|
||||
## Custom Request Timeouts
|
||||
|
||||
*NOTE:* We do not recommend decreasing the timeout for non-read-only calls (e.g. charge creation), since even if you locally timeout, the request on Stripe's side can still complete. If you are decreasing timeouts on these calls, make sure to use [idempotency tokens](https://stripe.com/docs/api/php#idempotent_requests) to avoid executing the same transaction twice as a result of timeout retry logic.
|
||||
|
||||
To modify request timeouts (connect or total, in seconds) you'll need to tell the API client to use a CurlClient other than its default. You'll set the timeouts in that CurlClient.
|
||||
|
||||
```php
|
||||
// set up your tweaked Curl client
|
||||
$curl = new \Stripe\HttpClient\CurlClient();
|
||||
$curl->setTimeout(10); // default is \Stripe\HttpClient\CurlClient::DEFAULT_TIMEOUT
|
||||
$curl->setConnectTimeout(5); // default is \Stripe\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT
|
||||
|
||||
echo $curl->getTimeout(); // 10
|
||||
echo $curl->getConnectTimeout(); // 5
|
||||
|
||||
// tell Stripe to use the tweaked client
|
||||
\Stripe\ApiRequestor::setHttpClient($curl);
|
||||
|
||||
// use the Stripe API client as you normally would
|
||||
```
|
||||
|
||||
## Custom cURL Options (e.g. proxies)
|
||||
|
||||
Need to set a proxy for your requests? Pass in the requisite `CURLOPT_*` array to the CurlClient constructor, using the same syntax as `curl_stopt_array()`. This will set the default cURL options for each HTTP request made by the SDK, though many more common options (e.g. timeouts; see above on how to set those) will be overridden by the client even if set here.
|
||||
|
||||
```php
|
||||
// set up your tweaked Curl client
|
||||
$curl = new \Stripe\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
|
||||
// tell Stripe to use the tweaked client
|
||||
\Stripe\ApiRequestor::setHttpClient($curl);
|
||||
```
|
||||
|
||||
Alternately, a callable can be passed to the CurlClient constructor that returns the above array based on request inputs. See `testDefaultOptions()` in `tests/CurlClientTest.php` for an example of this behavior. Note that the callable is called at the beginning of every API request, before the request is sent.
|
||||
|
||||
### Configuring a Logger
|
||||
|
||||
The library does minimal logging, but it can be configured
|
||||
with a [`PSR-3` compatible logger][psr3] so that messages
|
||||
end up there instead of `error_log`:
|
||||
|
||||
```php
|
||||
\Stripe\Stripe::setLogger($logger);
|
||||
```
|
||||
|
||||
### Accessing response data
|
||||
|
||||
You can access the data from the last API response on any object via `getLastResponse()`.
|
||||
|
||||
```php
|
||||
$charge = \Stripe\Charge::create(['amount' => 2000, 'currency' => 'usd', 'source' => 'tok_visa']);
|
||||
echo $charge->getLastResponse()->headers['Request-Id'];
|
||||
```
|
||||
|
||||
### SSL / TLS compatibility issues
|
||||
|
||||
Stripe's API now requires that [all connections use TLS 1.2](https://stripe.com/blog/upgrading-tls). Some systems (most notably some older CentOS and RHEL versions) are capable of using TLS 1.2 but will use TLS 1.0 or 1.1 by default. In this case, you'd get an `invalid_request_error` with the following error message: "Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at [https://stripe.com/blog/upgrading-tls](https://stripe.com/blog/upgrading-tls).".
|
||||
|
||||
The recommended course of action is to [upgrade your cURL and OpenSSL packages](https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#php) so that TLS 1.2 is used by default, but if that is not possible, you might be able to solve the issue by setting the `CURLOPT_SSLVERSION` option to either `CURL_SSLVERSION_TLSv1` or `CURL_SSLVERSION_TLSv1_2`:
|
||||
|
||||
```php
|
||||
$curl = new \Stripe\HttpClient\CurlClient([CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1]);
|
||||
\Stripe\ApiRequestor::setHttpClient($curl);
|
||||
```
|
||||
|
||||
### Per-request Configuration
|
||||
|
||||
For apps that need to use multiple keys during the lifetime of a process, like
|
||||
one that uses [Stripe Connect][connect], it's also possible to set a
|
||||
per-request key and/or account:
|
||||
|
||||
```php
|
||||
\Stripe\Charge::all([], [
|
||||
'api_key' => 'sk_test_...',
|
||||
'stripe_account' => 'acct_...'
|
||||
]);
|
||||
|
||||
\Stripe\Charge::retrieve("ch_18atAXCdGbJFKhCuBAa4532Z", [
|
||||
'api_key' => 'sk_test_...',
|
||||
'stripe_account' => 'acct_...'
|
||||
]);
|
||||
```
|
||||
|
||||
### Configuring CA Bundles
|
||||
|
||||
By default, the library will use its own internal bundle of known CA
|
||||
certificates, but it's possible to configure your own:
|
||||
|
||||
```php
|
||||
\Stripe\Stripe::setCABundlePath("path/to/ca/bundle");
|
||||
```
|
||||
|
||||
### Configuring Automatic Retries
|
||||
|
||||
The library can be configured to automatically retry requests that fail due to
|
||||
an intermittent network problem:
|
||||
|
||||
```php
|
||||
\Stripe\Stripe::setMaxNetworkRetries(2);
|
||||
```
|
||||
|
||||
[Idempotency keys][idempotency-keys] are added to requests to guarantee that
|
||||
retries are safe.
|
||||
|
||||
### Request latency telemetry
|
||||
|
||||
By default, the library sends request latency telemetry to Stripe. These
|
||||
numbers help Stripe improve the overall latency of its API for all users.
|
||||
|
||||
You can disable this behavior if you prefer:
|
||||
|
||||
```php
|
||||
\Stripe\Stripe::setEnableTelemetry(false);
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Get [Composer][composer]. For example, on Mac OS:
|
||||
|
||||
```bash
|
||||
brew install composer
|
||||
```
|
||||
|
||||
Install dependencies:
|
||||
|
||||
```bash
|
||||
composer install
|
||||
```
|
||||
|
||||
The test suite depends on [stripe-mock], so make sure to fetch and run it from a
|
||||
background terminal ([stripe-mock's README][stripe-mock] also contains
|
||||
instructions for installing via Homebrew and other methods):
|
||||
|
||||
```bash
|
||||
go get -u github.com/stripe/stripe-mock
|
||||
stripe-mock
|
||||
```
|
||||
|
||||
Install dependencies as mentioned above (which will resolve [PHPUnit](http://packagist.org/packages/phpunit/phpunit)), then you can run the test suite:
|
||||
|
||||
```bash
|
||||
./vendor/bin/phpunit
|
||||
```
|
||||
|
||||
Or to run an individual test file:
|
||||
|
||||
```bash
|
||||
./vendor/bin/phpunit tests/UtilTest.php
|
||||
```
|
||||
|
||||
Update bundled CA certificates from the [Mozilla cURL release][curl]:
|
||||
|
||||
```bash
|
||||
./update_certs.php
|
||||
```
|
||||
|
||||
The library uses [PHP CS Fixer][php-cs-fixer] for code formatting. Code must be formatted before PRs are submitted, otherwise CI will fail. Run the formatter with:
|
||||
|
||||
```bash
|
||||
./vendor/bin/php-cs-fixer fix -v .
|
||||
```
|
||||
|
||||
## Attention plugin developers
|
||||
|
||||
Are you writing a plugin that integrates Stripe and embeds our library? Then please use the `setAppInfo` function to identify your plugin. For example:
|
||||
|
||||
```php
|
||||
\Stripe\Stripe::setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
|
||||
```
|
||||
|
||||
The method should be called once, before any request is sent to the API. The second and third parameters are optional.
|
||||
|
||||
### SSL / TLS configuration option
|
||||
|
||||
See the "SSL / TLS compatibility issues" paragraph above for full context. If you want to ensure that your plugin can be used on all systems, you should add a configuration option to let your users choose between different values for `CURLOPT_SSLVERSION`: none (default), `CURL_SSLVERSION_TLSv1` and `CURL_SSLVERSION_TLSv1_2`.
|
||||
|
||||
[composer]: https://getcomposer.org/
|
||||
[connect]: https://stripe.com/connect
|
||||
[curl]: http://curl.haxx.se/docs/caextract.html
|
||||
[idempotency-keys]: https://stripe.com/docs/api/php#idempotent_requests
|
||||
[php-cs-fixer]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
|
||||
[psr3]: http://www.php-fig.org/psr/psr-3/
|
||||
[stripe-mock]: https://github.com/stripe/stripe-mock
|
||||
|
|
@ -0,0 +1 @@
|
|||
7.0.2
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
chdir(dirname(__FILE__));
|
||||
|
||||
$autoload = (int)$argv[1];
|
||||
$returnStatus = null;
|
||||
|
||||
if (!$autoload) {
|
||||
// Modify composer to not autoload Stripe
|
||||
$composer = json_decode(file_get_contents('composer.json'), true);
|
||||
unset($composer['autoload']);
|
||||
unset($composer['require-dev']['squizlabs/php_codesniffer']);
|
||||
file_put_contents('composer.json', json_encode($composer, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
passthru('composer update', $returnStatus);
|
||||
if ($returnStatus !== 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ($autoload) {
|
||||
// Only run CS on 1 of the 2 environments
|
||||
passthru(
|
||||
'./vendor/bin/phpcs --standard=PSR2 -n lib tests *.php',
|
||||
$returnStatus
|
||||
);
|
||||
if ($returnStatus !== 0) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
$config = $autoload ? 'phpunit.xml' : 'phpunit.no_autoload.xml';
|
||||
passthru("./vendor/bin/phpunit -c $config", $returnStatus);
|
||||
if ($returnStatus !== 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "stripe/stripe-php",
|
||||
"description": "Stripe PHP Library",
|
||||
"keywords": [
|
||||
"stripe",
|
||||
"payment processing",
|
||||
"api"
|
||||
],
|
||||
"homepage": "https://stripe.com/",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Stripe and contributors",
|
||||
"homepage": "https://github.com/stripe/stripe-php/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.6.0",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"squizlabs/php_codesniffer": "^3.3",
|
||||
"symfony/process": "~3.4",
|
||||
"friendsofphp/php-cs-fixer": "^2.15"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Stripe\\" : "lib/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
// Stripe singleton
|
||||
require(dirname(__FILE__) . '/lib/Stripe.php');
|
||||
|
||||
// Utilities
|
||||
require(dirname(__FILE__) . '/lib/Util/CaseInsensitiveArray.php');
|
||||
require(dirname(__FILE__) . '/lib/Util/LoggerInterface.php');
|
||||
require(dirname(__FILE__) . '/lib/Util/DefaultLogger.php');
|
||||
require(dirname(__FILE__) . '/lib/Util/RandomGenerator.php');
|
||||
require(dirname(__FILE__) . '/lib/Util/RequestOptions.php');
|
||||
require(dirname(__FILE__) . '/lib/Util/Set.php');
|
||||
require(dirname(__FILE__) . '/lib/Util/Util.php');
|
||||
|
||||
// HttpClient
|
||||
require(dirname(__FILE__) . '/lib/HttpClient/ClientInterface.php');
|
||||
require(dirname(__FILE__) . '/lib/HttpClient/CurlClient.php');
|
||||
|
||||
// Exceptions
|
||||
require(dirname(__FILE__) . '/lib/Exception/ExceptionInterface.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/ApiErrorException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/ApiConnectionException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/AuthenticationException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/BadMethodCallException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/CardException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/IdempotencyException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/InvalidArgumentException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/InvalidRequestException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/PermissionException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/RateLimitException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/SignatureVerificationException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/UnexpectedValueException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/UnknownApiErrorException.php');
|
||||
|
||||
// OAuth exceptions
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/ExceptionInterface.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/OAuthErrorException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/InvalidClientException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/InvalidGrantException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/InvalidRequestException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/InvalidScopeException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/UnknownOAuthErrorException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/UnsupportedGrantTypeException.php');
|
||||
require(dirname(__FILE__) . '/lib/Exception/OAuth/UnsupportedResponseTypeException.php');
|
||||
|
||||
// API operations
|
||||
require(dirname(__FILE__) . '/lib/ApiOperations/All.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiOperations/Create.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiOperations/Delete.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiOperations/NestedResource.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiOperations/Request.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiOperations/Retrieve.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiOperations/Update.php');
|
||||
|
||||
// Plumbing
|
||||
require(dirname(__FILE__) . '/lib/ApiResponse.php');
|
||||
require(dirname(__FILE__) . '/lib/RequestTelemetry.php');
|
||||
require(dirname(__FILE__) . '/lib/StripeObject.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiRequestor.php');
|
||||
require(dirname(__FILE__) . '/lib/ApiResource.php');
|
||||
require(dirname(__FILE__) . '/lib/SingletonApiResource.php');
|
||||
|
||||
// Stripe API Resources
|
||||
require(dirname(__FILE__) . '/lib/Account.php');
|
||||
require(dirname(__FILE__) . '/lib/AccountLink.php');
|
||||
require(dirname(__FILE__) . '/lib/AlipayAccount.php');
|
||||
require(dirname(__FILE__) . '/lib/ApplePayDomain.php');
|
||||
require(dirname(__FILE__) . '/lib/ApplicationFee.php');
|
||||
require(dirname(__FILE__) . '/lib/ApplicationFeeRefund.php');
|
||||
require(dirname(__FILE__) . '/lib/Balance.php');
|
||||
require(dirname(__FILE__) . '/lib/BalanceTransaction.php');
|
||||
require(dirname(__FILE__) . '/lib/BankAccount.php');
|
||||
require(dirname(__FILE__) . '/lib/BitcoinReceiver.php');
|
||||
require(dirname(__FILE__) . '/lib/BitcoinTransaction.php');
|
||||
require(dirname(__FILE__) . '/lib/Capability.php');
|
||||
require(dirname(__FILE__) . '/lib/Card.php');
|
||||
require(dirname(__FILE__) . '/lib/Charge.php');
|
||||
require(dirname(__FILE__) . '/lib/Checkout/Session.php');
|
||||
require(dirname(__FILE__) . '/lib/Collection.php');
|
||||
require(dirname(__FILE__) . '/lib/CountrySpec.php');
|
||||
require(dirname(__FILE__) . '/lib/Coupon.php');
|
||||
require(dirname(__FILE__) . '/lib/CreditNote.php');
|
||||
require(dirname(__FILE__) . '/lib/Customer.php');
|
||||
require(dirname(__FILE__) . '/lib/CustomerBalanceTransaction.php');
|
||||
require(dirname(__FILE__) . '/lib/Discount.php');
|
||||
require(dirname(__FILE__) . '/lib/Dispute.php');
|
||||
require(dirname(__FILE__) . '/lib/EphemeralKey.php');
|
||||
require(dirname(__FILE__) . '/lib/ErrorObject.php');
|
||||
require(dirname(__FILE__) . '/lib/Event.php');
|
||||
require(dirname(__FILE__) . '/lib/ExchangeRate.php');
|
||||
require(dirname(__FILE__) . '/lib/File.php');
|
||||
require(dirname(__FILE__) . '/lib/FileLink.php');
|
||||
require(dirname(__FILE__) . '/lib/Invoice.php');
|
||||
require(dirname(__FILE__) . '/lib/InvoiceItem.php');
|
||||
require(dirname(__FILE__) . '/lib/InvoiceLineItem.php');
|
||||
require(dirname(__FILE__) . '/lib/Issuing/Authorization.php');
|
||||
require(dirname(__FILE__) . '/lib/Issuing/Card.php');
|
||||
require(dirname(__FILE__) . '/lib/Issuing/CardDetails.php');
|
||||
require(dirname(__FILE__) . '/lib/Issuing/Cardholder.php');
|
||||
require(dirname(__FILE__) . '/lib/Issuing/Dispute.php');
|
||||
require(dirname(__FILE__) . '/lib/Issuing/Transaction.php');
|
||||
require(dirname(__FILE__) . '/lib/LoginLink.php');
|
||||
require(dirname(__FILE__) . '/lib/Order.php');
|
||||
require(dirname(__FILE__) . '/lib/OrderItem.php');
|
||||
require(dirname(__FILE__) . '/lib/OrderReturn.php');
|
||||
require(dirname(__FILE__) . '/lib/PaymentIntent.php');
|
||||
require(dirname(__FILE__) . '/lib/PaymentMethod.php');
|
||||
require(dirname(__FILE__) . '/lib/Payout.php');
|
||||
require(dirname(__FILE__) . '/lib/Person.php');
|
||||
require(dirname(__FILE__) . '/lib/Plan.php');
|
||||
require(dirname(__FILE__) . '/lib/Product.php');
|
||||
require(dirname(__FILE__) . '/lib/Radar/EarlyFraudWarning.php');
|
||||
require(dirname(__FILE__) . '/lib/Radar/ValueList.php');
|
||||
require(dirname(__FILE__) . '/lib/Radar/ValueListItem.php');
|
||||
require(dirname(__FILE__) . '/lib/Recipient.php');
|
||||
require(dirname(__FILE__) . '/lib/RecipientTransfer.php');
|
||||
require(dirname(__FILE__) . '/lib/Refund.php');
|
||||
require(dirname(__FILE__) . '/lib/Reporting/ReportRun.php');
|
||||
require(dirname(__FILE__) . '/lib/Reporting/ReportType.php');
|
||||
require(dirname(__FILE__) . '/lib/Review.php');
|
||||
require(dirname(__FILE__) . '/lib/SetupIntent.php');
|
||||
require(dirname(__FILE__) . '/lib/SKU.php');
|
||||
require(dirname(__FILE__) . '/lib/Sigma/ScheduledQueryRun.php');
|
||||
require(dirname(__FILE__) . '/lib/Source.php');
|
||||
require(dirname(__FILE__) . '/lib/SourceTransaction.php');
|
||||
require(dirname(__FILE__) . '/lib/Subscription.php');
|
||||
require(dirname(__FILE__) . '/lib/SubscriptionItem.php');
|
||||
require(dirname(__FILE__) . '/lib/SubscriptionSchedule.php');
|
||||
require(dirname(__FILE__) . '/lib/TaxId.php');
|
||||
require(dirname(__FILE__) . '/lib/TaxRate.php');
|
||||
require(dirname(__FILE__) . '/lib/Terminal/ConnectionToken.php');
|
||||
require(dirname(__FILE__) . '/lib/Terminal/Location.php');
|
||||
require(dirname(__FILE__) . '/lib/Terminal/Reader.php');
|
||||
require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
|
||||
require(dirname(__FILE__) . '/lib/Token.php');
|
||||
require(dirname(__FILE__) . '/lib/Topup.php');
|
||||
require(dirname(__FILE__) . '/lib/Transfer.php');
|
||||
require(dirname(__FILE__) . '/lib/TransferReversal.php');
|
||||
require(dirname(__FILE__) . '/lib/UsageRecord.php');
|
||||
require(dirname(__FILE__) . '/lib/UsageRecordSummary.php');
|
||||
|
||||
// OAuth
|
||||
require(dirname(__FILE__) . '/lib/OAuth.php');
|
||||
require(dirname(__FILE__) . '/lib/OAuthErrorObject.php');
|
||||
|
||||
// Webhooks
|
||||
require(dirname(__FILE__) . '/lib/Webhook.php');
|
||||
require(dirname(__FILE__) . '/lib/WebhookEndpoint.php');
|
||||
require(dirname(__FILE__) . '/lib/WebhookSignature.php');
|
||||
|
|
@ -0,0 +1,426 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property mixed $business_profile
|
||||
* @property string $business_type
|
||||
* @property mixed $capabilities
|
||||
* @property bool $charges_enabled
|
||||
* @property mixed $company
|
||||
* @property string $country
|
||||
* @property int $created
|
||||
* @property string $default_currency
|
||||
* @property bool $details_submitted
|
||||
* @property string $email
|
||||
* @property Collection $external_accounts
|
||||
* @property mixed $individual
|
||||
* @property StripeObject $metadata
|
||||
* @property bool $payouts_enabled
|
||||
* @property mixed $requirements
|
||||
* @property mixed $settings
|
||||
* @property mixed $tos_acceptance
|
||||
* @property string $type
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Account extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "account";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Create;
|
||||
use ApiOperations\Delete;
|
||||
use ApiOperations\NestedResource;
|
||||
use ApiOperations\Retrieve {
|
||||
retrieve as protected _retrieve;
|
||||
}
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of an account's business type.
|
||||
* @link https://stripe.com/docs/api/accounts/object#account_object-business_type
|
||||
*/
|
||||
const BUSINESS_TYPE_COMPANY = 'company';
|
||||
const BUSINESS_TYPE_INDIVIDUAL = 'individual';
|
||||
|
||||
/**
|
||||
* Possible string representations of an account's capabilities.
|
||||
* @link https://stripe.com/docs/api/accounts/object#account_object-capabilities
|
||||
*/
|
||||
const CAPABILITY_CARD_PAYMENTS = 'card_payments';
|
||||
const CAPABILITY_LEGACY_PAYMENTS = 'legacy_payments';
|
||||
const CAPABILITY_PLATFORM_PAYMENTS = 'platform_payments';
|
||||
|
||||
/**
|
||||
* Possible string representations of an account's capability status.
|
||||
* @link https://stripe.com/docs/api/accounts/object#account_object-capabilities
|
||||
*/
|
||||
const CAPABILITY_STATUS_ACTIVE = 'active';
|
||||
const CAPABILITY_STATUS_INACTIVE = 'inactive';
|
||||
const CAPABILITY_STATUS_PENDING = 'pending';
|
||||
|
||||
/**
|
||||
* Possible string representations of an account's type.
|
||||
* @link https://stripe.com/docs/api/accounts/object#account_object-type
|
||||
*/
|
||||
const TYPE_CUSTOM = 'custom';
|
||||
const TYPE_EXPRESS = 'express';
|
||||
const TYPE_STANDARD = 'standard';
|
||||
|
||||
public static function getSavedNestedResources()
|
||||
{
|
||||
static $savedNestedResources = null;
|
||||
if ($savedNestedResources === null) {
|
||||
$savedNestedResources = new Util\Set([
|
||||
'external_account',
|
||||
'bank_account',
|
||||
]);
|
||||
}
|
||||
return $savedNestedResources;
|
||||
}
|
||||
|
||||
const PATH_CAPABILITIES = '/capabilities';
|
||||
const PATH_EXTERNAL_ACCOUNTS = '/external_accounts';
|
||||
const PATH_LOGIN_LINKS = '/login_links';
|
||||
const PATH_PERSONS = '/persons';
|
||||
|
||||
public function instanceUrl()
|
||||
{
|
||||
if ($this['id'] === null) {
|
||||
return '/v1/account';
|
||||
} else {
|
||||
return parent::instanceUrl();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string|null $id The ID of the account to retrieve, or an
|
||||
* options array containing an `id` key.
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public static function retrieve($id = null, $opts = null)
|
||||
{
|
||||
if (!$opts && is_string($id) && substr($id, 0, 3) === 'sk_') {
|
||||
$opts = $id;
|
||||
$id = null;
|
||||
}
|
||||
return self::_retrieve($id, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Account The rejected account.
|
||||
*/
|
||||
public function reject($params = null, $opts = null)
|
||||
{
|
||||
$url = $this->instanceUrl() . '/reject';
|
||||
list($response, $opts) = $this->_request('post', $url, $params, $opts);
|
||||
$this->refreshFrom($response, $opts);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $clientId
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return StripeObject Object containing the response from the API.
|
||||
*/
|
||||
public function deauthorize($clientId = null, $opts = null)
|
||||
{
|
||||
$params = [
|
||||
'client_id' => $clientId,
|
||||
'stripe_user_id' => $this->id,
|
||||
];
|
||||
return OAuth::deauthorize($params, $opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Capabilities methods
|
||||
* We can not add the capabilities() method today as the Account object already has a
|
||||
* capabilities property which is a hash and not the sub-list of capabilities.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the capability belongs.
|
||||
* @param string $capabilityId The ID of the capability to retrieve.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Capability
|
||||
*/
|
||||
public static function retrieveCapability($id, $capabilityId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_retrieveNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the capability belongs.
|
||||
* @param string $capabilityId The ID of the capability to update.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @return Capability
|
||||
*/
|
||||
public static function updateCapability($id, $capabilityId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_updateNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account on which to retrieve the capabilities.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of capabilities.
|
||||
*/
|
||||
public static function allCapabilities($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_allNestedResources($id, static::PATH_CAPABILITIES, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account on which to create the external account.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return BankAccount|Card
|
||||
*/
|
||||
public static function createExternalAccount($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_createNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the external account belongs.
|
||||
* @param string $externalAccountId The ID of the external account to retrieve.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return BankAccount|Card
|
||||
*/
|
||||
public static function retrieveExternalAccount($id, $externalAccountId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_retrieveNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the external account belongs.
|
||||
* @param string $externalAccountId The ID of the external account to update.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return BankAccount|Card
|
||||
*/
|
||||
public static function updateExternalAccount($id, $externalAccountId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_updateNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the external account belongs.
|
||||
* @param string $externalAccountId The ID of the external account to delete.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return BankAccount|Card
|
||||
*/
|
||||
public static function deleteExternalAccount($id, $externalAccountId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_deleteNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account on which to retrieve the external accounts.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of external accounts (BankAccount or Card).
|
||||
*/
|
||||
public static function allExternalAccounts($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_allNestedResources($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account on which to create the login link.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return LoginLink
|
||||
*/
|
||||
public static function createLoginLink($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_createNestedResource($id, static::PATH_LOGIN_LINKS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of persons.
|
||||
*/
|
||||
public function persons($params = null, $options = null)
|
||||
{
|
||||
$url = $this->instanceUrl() . '/persons';
|
||||
list($response, $opts) = $this->_request('get', $url, $params, $options);
|
||||
$obj = Util\Util::convertToStripeObject($response, $opts);
|
||||
$obj->setLastResponse($response);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account on which to create the person.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Person
|
||||
*/
|
||||
public static function createPerson($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_createNestedResource($id, static::PATH_PERSONS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the person belongs.
|
||||
* @param string $personId The ID of the person to retrieve.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Person
|
||||
*/
|
||||
public static function retrievePerson($id, $personId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_retrieveNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the person belongs.
|
||||
* @param string $personId The ID of the person to update.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Person
|
||||
*/
|
||||
public static function updatePerson($id, $personId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_updateNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account to which the person belongs.
|
||||
* @param string $personId The ID of the person to delete.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Person
|
||||
*/
|
||||
public static function deletePerson($id, $personId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_deleteNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id The ID of the account on which to retrieve the persons.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of persons.
|
||||
*/
|
||||
public static function allPersons($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_allNestedResources($id, static::PATH_PERSONS, $params, $opts);
|
||||
}
|
||||
|
||||
public function serializeParameters($force = false)
|
||||
{
|
||||
$update = parent::serializeParameters($force);
|
||||
if (isset($this->_values['legal_entity'])) {
|
||||
$entity = $this['legal_entity'];
|
||||
if (isset($entity->_values['additional_owners'])) {
|
||||
$owners = $entity['additional_owners'];
|
||||
$entityUpdate = isset($update['legal_entity']) ? $update['legal_entity'] : [];
|
||||
$entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners);
|
||||
$update['legal_entity'] = $entityUpdate;
|
||||
}
|
||||
}
|
||||
if (isset($this->_values['individual'])) {
|
||||
$individual = $this['individual'];
|
||||
if (($individual instanceof Person) && !isset($update['individual'])) {
|
||||
$update['individual'] = $individual->serializeParameters($force);
|
||||
}
|
||||
}
|
||||
return $update;
|
||||
}
|
||||
|
||||
private function serializeAdditionalOwners($legalEntity, $additionalOwners)
|
||||
{
|
||||
if (isset($legalEntity->_originalValues['additional_owners'])) {
|
||||
$originalValue = $legalEntity->_originalValues['additional_owners'];
|
||||
} else {
|
||||
$originalValue = [];
|
||||
}
|
||||
if (($originalValue) && (count($originalValue) > count($additionalOwners))) {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
"You cannot delete an item from an array, you must instead set a new array"
|
||||
);
|
||||
}
|
||||
|
||||
$updateArr = [];
|
||||
foreach ($additionalOwners as $i => $v) {
|
||||
$update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v;
|
||||
|
||||
if ($update !== []) {
|
||||
if (!$originalValue ||
|
||||
!array_key_exists($i, $originalValue) ||
|
||||
($update != $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
|
||||
$updateArr[$i] = $update;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $updateArr;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class AccountLink
|
||||
*
|
||||
* @property string $object
|
||||
* @property int $created
|
||||
* @property int $expires_at
|
||||
* @property string $url
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class AccountLink extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "account_link";
|
||||
|
||||
use ApiOperations\Create;
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class AlipayAccount
|
||||
*
|
||||
* @package Stripe
|
||||
*
|
||||
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
|
||||
* @link https://stripe.com/docs/sources/alipay
|
||||
*/
|
||||
class AlipayAccount extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "alipay_account";
|
||||
|
||||
use ApiOperations\Delete;
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* @return string The instance URL for this resource. It needs to be special
|
||||
* cased because it doesn't fit into the standard resource pattern.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
if ($this['customer']) {
|
||||
$base = Customer::classUrl();
|
||||
$parent = $this['customer'];
|
||||
$path = 'sources';
|
||||
} else {
|
||||
$msg = "Alipay accounts cannot be accessed without a customer ID.";
|
||||
throw new Exception\UnexpectedValueException($msg);
|
||||
}
|
||||
$parentExtn = urlencode(Util\Util::utf8($parent));
|
||||
$extn = urlencode(Util\Util::utf8($this['id']));
|
||||
return "$base/$parentExtn/$path/$extn";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $_id
|
||||
* @param array|string|null $_opts
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*
|
||||
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
|
||||
* @link https://stripe.com/docs/sources/alipay
|
||||
*/
|
||||
public static function retrieve($_id, $_opts = null)
|
||||
{
|
||||
$msg = "Alipay accounts cannot be retrieved without a customer ID. " .
|
||||
"Retrieve an Alipay account using `Customer::retrieveSource(" .
|
||||
"'customer_id', 'alipay_account_id')`.";
|
||||
throw new Exception\BadMethodCallException($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $_id
|
||||
* @param array|null $_params
|
||||
* @param array|string|null $_options
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*
|
||||
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
|
||||
* @link https://stripe.com/docs/sources/alipay
|
||||
*/
|
||||
public static function update($_id, $_params = null, $_options = null)
|
||||
{
|
||||
$msg = "Alipay accounts cannot be updated without a customer ID. " .
|
||||
"Update an Alipay account using `Customer::updateSource(" .
|
||||
"'customer_id', 'alipay_account_id', \$updateParams)`.";
|
||||
throw new Exception\BadMethodCallException($msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\ApiOperations;
|
||||
|
||||
/**
|
||||
* Trait for listable resources. Adds a `all()` static method to the class.
|
||||
*
|
||||
* This trait should only be applied to classes that derive from StripeObject.
|
||||
*/
|
||||
trait All
|
||||
{
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return \Stripe\Collection of ApiResources
|
||||
*/
|
||||
public static function all($params = null, $opts = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
$url = static::classUrl();
|
||||
|
||||
list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
|
||||
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
|
||||
if (!($obj instanceof \Stripe\Collection)) {
|
||||
throw new \Stripe\Exception\UnexpectedValueException(
|
||||
'Expected type ' . \Stripe\Collection::class . ', got "' . get_class($obj) . '" instead.'
|
||||
);
|
||||
}
|
||||
$obj->setLastResponse($response);
|
||||
$obj->setFilters($params);
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\ApiOperations;
|
||||
|
||||
/**
|
||||
* Trait for creatable resources. Adds a `create()` static method to the class.
|
||||
*
|
||||
* This trait should only be applied to classes that derive from StripeObject.
|
||||
*/
|
||||
trait Create
|
||||
{
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return static The created resource.
|
||||
*/
|
||||
public static function create($params = null, $options = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
$url = static::classUrl();
|
||||
|
||||
list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
|
||||
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
|
||||
$obj->setLastResponse($response);
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\ApiOperations;
|
||||
|
||||
/**
|
||||
* Trait for deletable resources. Adds a `delete()` method to the class.
|
||||
*
|
||||
* This trait should only be applied to classes that derive from StripeObject.
|
||||
*/
|
||||
trait Delete
|
||||
{
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return static The deleted resource.
|
||||
*/
|
||||
public function delete($params = null, $opts = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
|
||||
$url = $this->instanceUrl();
|
||||
list($response, $opts) = $this->_request('delete', $url, $params, $opts);
|
||||
$this->refreshFrom($response, $opts);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\ApiOperations;
|
||||
|
||||
/**
|
||||
* Trait for resources that have nested resources.
|
||||
*
|
||||
* This trait should only be applied to classes that derive from StripeObject.
|
||||
*/
|
||||
trait NestedResource
|
||||
{
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @return \Stripe\StripeObject
|
||||
*/
|
||||
protected static function _nestedResourceOperation($method, $url, $params = null, $options = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
|
||||
list($response, $opts) = static::_staticRequest($method, $url, $params, $options);
|
||||
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
|
||||
$obj->setLastResponse($response);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $nestedPath
|
||||
* @param string|null $nestedId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function _nestedResourceUrl($id, $nestedPath, $nestedId = null)
|
||||
{
|
||||
$url = static::resourceUrl($id) . $nestedPath;
|
||||
if ($nestedId !== null) {
|
||||
$url .= "/$nestedId";
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $nestedPath
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return \Stripe\StripeObject
|
||||
*/
|
||||
protected static function _createNestedResource($id, $nestedPath, $params = null, $options = null)
|
||||
{
|
||||
$url = static::_nestedResourceUrl($id, $nestedPath);
|
||||
return self::_nestedResourceOperation('post', $url, $params, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $nestedPath
|
||||
* @param string|null $nestedId
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return \Stripe\StripeObject
|
||||
*/
|
||||
protected static function _retrieveNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
|
||||
{
|
||||
$url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
|
||||
return self::_nestedResourceOperation('get', $url, $params, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $nestedPath
|
||||
* @param string|null $nestedId
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return \Stripe\StripeObject
|
||||
*/
|
||||
protected static function _updateNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
|
||||
{
|
||||
$url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
|
||||
return self::_nestedResourceOperation('post', $url, $params, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $nestedPath
|
||||
* @param string|null $nestedId
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return \Stripe\StripeObject
|
||||
*/
|
||||
protected static function _deleteNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
|
||||
{
|
||||
$url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
|
||||
return self::_nestedResourceOperation('delete', $url, $params, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $nestedPath
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return \Stripe\StripeObject
|
||||
*/
|
||||
protected static function _allNestedResources($id, $nestedPath, $params = null, $options = null)
|
||||
{
|
||||
$url = static::_nestedResourceUrl($id, $nestedPath);
|
||||
return self::_nestedResourceOperation('get', $url, $params, $options);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\ApiOperations;
|
||||
|
||||
/**
|
||||
* Trait for resources that need to make API requests.
|
||||
*
|
||||
* This trait should only be applied to classes that derive from StripeObject.
|
||||
*/
|
||||
trait Request
|
||||
{
|
||||
/**
|
||||
* @param array|null|mixed $params The list of parameters to validate
|
||||
*
|
||||
* @throws \Stripe\Exception\InvalidArgumentException if $params exists and is not an array
|
||||
*/
|
||||
protected static function _validateParams($params = null)
|
||||
{
|
||||
if ($params && !is_array($params)) {
|
||||
$message = "You must pass an array as the first argument to Stripe API "
|
||||
. "method calls. (HINT: an example call to create a charge "
|
||||
. "would be: \"Stripe\\Charge::create(['amount' => 100, "
|
||||
. "'currency' => 'usd', 'source' => 'tok_1234'])\")";
|
||||
throw new \Stripe\Exception\InvalidArgumentException($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method HTTP method ('get', 'post', etc.)
|
||||
* @param string $url URL for the request
|
||||
* @param array $params list of parameters for the request
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return array tuple containing (the JSON response, $options)
|
||||
*/
|
||||
protected function _request($method, $url, $params = [], $options = null)
|
||||
{
|
||||
$opts = $this->_opts->merge($options);
|
||||
list($resp, $options) = static::_staticRequest($method, $url, $params, $opts);
|
||||
$this->setLastResponse($resp);
|
||||
return [$resp->json, $options];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method HTTP method ('get', 'post', etc.)
|
||||
* @param string $url URL for the request
|
||||
* @param array $params list of parameters for the request
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return array tuple containing (the JSON response, $options)
|
||||
*/
|
||||
protected static function _staticRequest($method, $url, $params, $options)
|
||||
{
|
||||
$opts = \Stripe\Util\RequestOptions::parse($options);
|
||||
$baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl();
|
||||
$requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl);
|
||||
list($response, $opts->apiKey) = $requestor->request($method, $url, $params, $opts->headers);
|
||||
$opts->discardNonPersistentHeaders();
|
||||
return [$response, $opts];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\ApiOperations;
|
||||
|
||||
/**
|
||||
* Trait for retrievable resources. Adds a `retrieve()` static method to the
|
||||
* class.
|
||||
*
|
||||
* This trait should only be applied to classes that derive from StripeObject.
|
||||
*/
|
||||
trait Retrieve
|
||||
{
|
||||
/**
|
||||
* @param array|string $id The ID of the API resource to retrieve,
|
||||
* or an options array containing an `id` key.
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function retrieve($id, $opts = null)
|
||||
{
|
||||
$opts = \Stripe\Util\RequestOptions::parse($opts);
|
||||
$instance = new static($id, $opts);
|
||||
$instance->refresh();
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\ApiOperations;
|
||||
|
||||
/**
|
||||
* Trait for updatable resources. Adds an `update()` static method and a
|
||||
* `save()` method to the class.
|
||||
*
|
||||
* This trait should only be applied to classes that derive from StripeObject.
|
||||
*/
|
||||
trait Update
|
||||
{
|
||||
/**
|
||||
* @param string $id The ID of the resource to update.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return static The updated resource.
|
||||
*/
|
||||
public static function update($id, $params = null, $opts = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
$url = static::resourceUrl($id);
|
||||
|
||||
list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
|
||||
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
|
||||
$obj->setLastResponse($response);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return static The saved resource.
|
||||
*/
|
||||
public function save($opts = null)
|
||||
{
|
||||
$params = $this->serializeParameters();
|
||||
if (count($params) > 0) {
|
||||
$url = $this->instanceUrl();
|
||||
list($response, $opts) = $this->_request('post', $url, $params, $opts);
|
||||
$this->refreshFrom($response, $opts);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,463 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class ApiRequestor
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class ApiRequestor
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $_apiKey;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_apiBase;
|
||||
|
||||
/**
|
||||
* @var HttpClient\ClientInterface
|
||||
*/
|
||||
private static $_httpClient;
|
||||
|
||||
/**
|
||||
* @var RequestTelemetry
|
||||
*/
|
||||
private static $requestTelemetry;
|
||||
|
||||
/**
|
||||
* ApiRequestor constructor.
|
||||
*
|
||||
* @param string|null $apiKey
|
||||
* @param string|null $apiBase
|
||||
*/
|
||||
public function __construct($apiKey = null, $apiBase = null)
|
||||
{
|
||||
$this->_apiKey = $apiKey;
|
||||
if (!$apiBase) {
|
||||
$apiBase = Stripe::$apiBase;
|
||||
}
|
||||
$this->_apiBase = $apiBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a telemetry json blob for use in 'X-Stripe-Client-Telemetry' headers
|
||||
* @static
|
||||
*
|
||||
* @param RequestTelemetry $requestTelemetry
|
||||
* @return string
|
||||
*/
|
||||
private static function _telemetryJson($requestTelemetry)
|
||||
{
|
||||
$payload = array(
|
||||
'last_request_metrics' => array(
|
||||
'request_id' => $requestTelemetry->requestId,
|
||||
'request_duration_ms' => $requestTelemetry->requestDuration,
|
||||
));
|
||||
|
||||
$result = json_encode($payload);
|
||||
if ($result != false) {
|
||||
return $result;
|
||||
} else {
|
||||
Stripe::getLogger()->error("Serializing telemetry payload failed!");
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param ApiResource|bool|array|mixed $d
|
||||
*
|
||||
* @return ApiResource|array|string|mixed
|
||||
*/
|
||||
private static function _encodeObjects($d)
|
||||
{
|
||||
if ($d instanceof ApiResource) {
|
||||
return Util\Util::utf8($d->id);
|
||||
} elseif ($d === true) {
|
||||
return 'true';
|
||||
} elseif ($d === false) {
|
||||
return 'false';
|
||||
} elseif (is_array($d)) {
|
||||
$res = [];
|
||||
foreach ($d as $k => $v) {
|
||||
$res[$k] = self::_encodeObjects($v);
|
||||
}
|
||||
return $res;
|
||||
} else {
|
||||
return Util\Util::utf8($d);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array|null $params
|
||||
* @param array|null $headers
|
||||
*
|
||||
* @return array tuple containing (ApiReponse, API key)
|
||||
*
|
||||
* @throws Exception\ApiErrorException
|
||||
*/
|
||||
public function request($method, $url, $params = null, $headers = null)
|
||||
{
|
||||
$params = $params ?: [];
|
||||
$headers = $headers ?: [];
|
||||
list($rbody, $rcode, $rheaders, $myApiKey) =
|
||||
$this->_requestRaw($method, $url, $params, $headers);
|
||||
$json = $this->_interpretResponse($rbody, $rcode, $rheaders);
|
||||
$resp = new ApiResponse($rbody, $rcode, $rheaders, $json);
|
||||
return [$resp, $myApiKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rbody A JSON string.
|
||||
* @param int $rcode
|
||||
* @param array $rheaders
|
||||
* @param array $resp
|
||||
*
|
||||
* @throws Exception\UnexpectedValueException
|
||||
* @throws Exception\ApiErrorException
|
||||
*/
|
||||
public function handleErrorResponse($rbody, $rcode, $rheaders, $resp)
|
||||
{
|
||||
if (!is_array($resp) || !isset($resp['error'])) {
|
||||
$msg = "Invalid response object from API: $rbody "
|
||||
. "(HTTP response code was $rcode)";
|
||||
throw new Exception\UnexpectedValueException($msg, $rcode, $rbody, $resp, $rheaders);
|
||||
}
|
||||
|
||||
$errorData = $resp['error'];
|
||||
|
||||
$error = null;
|
||||
if (is_string($errorData)) {
|
||||
$error = self::_specificOAuthError($rbody, $rcode, $rheaders, $resp, $errorData);
|
||||
}
|
||||
if (!$error) {
|
||||
$error = self::_specificAPIError($rbody, $rcode, $rheaders, $resp, $errorData);
|
||||
}
|
||||
|
||||
throw $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param string $rbody
|
||||
* @param int $rcode
|
||||
* @param array $rheaders
|
||||
* @param array $resp
|
||||
* @param array $errorData
|
||||
*
|
||||
* @return Exception\ApiErrorException
|
||||
*/
|
||||
private static function _specificAPIError($rbody, $rcode, $rheaders, $resp, $errorData)
|
||||
{
|
||||
$msg = isset($errorData['message']) ? $errorData['message'] : null;
|
||||
$param = isset($errorData['param']) ? $errorData['param'] : null;
|
||||
$code = isset($errorData['code']) ? $errorData['code'] : null;
|
||||
$type = isset($errorData['type']) ? $errorData['type'] : null;
|
||||
$declineCode = isset($errorData['decline_code']) ? $errorData['decline_code'] : null;
|
||||
|
||||
switch ($rcode) {
|
||||
case 400:
|
||||
// 'rate_limit' code is deprecated, but left here for backwards compatibility
|
||||
// for API versions earlier than 2015-09-08
|
||||
if ($code == 'rate_limit') {
|
||||
return Exception\RateLimitException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code, $param);
|
||||
}
|
||||
if ($type == 'idempotency_error') {
|
||||
return Exception\IdempotencyException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code);
|
||||
}
|
||||
|
||||
// no break
|
||||
case 404:
|
||||
return Exception\InvalidRequestException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code, $param);
|
||||
case 401:
|
||||
return Exception\AuthenticationException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code);
|
||||
case 402:
|
||||
return Exception\CardException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code, $declineCode, $param);
|
||||
case 403:
|
||||
return Exception\PermissionException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code);
|
||||
case 429:
|
||||
return Exception\RateLimitException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code, $param);
|
||||
default:
|
||||
return Exception\UnknownApiErrorException::factory($msg, $rcode, $rbody, $resp, $rheaders, $code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param string|bool $rbody
|
||||
* @param int $rcode
|
||||
* @param array $rheaders
|
||||
* @param array $resp
|
||||
* @param string $errorCode
|
||||
*
|
||||
* @return Exception\OAuth\OAuthErrorException
|
||||
*/
|
||||
private static function _specificOAuthError($rbody, $rcode, $rheaders, $resp, $errorCode)
|
||||
{
|
||||
$description = isset($resp['error_description']) ? $resp['error_description'] : $errorCode;
|
||||
|
||||
switch ($errorCode) {
|
||||
case 'invalid_client':
|
||||
return Exception\OAuth\InvalidClientException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
|
||||
case 'invalid_grant':
|
||||
return Exception\OAuth\InvalidGrantException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
|
||||
case 'invalid_request':
|
||||
return Exception\OAuth\InvalidRequestException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
|
||||
case 'invalid_scope':
|
||||
return Exception\OAuth\InvalidScopeException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
|
||||
case 'unsupported_grant_type':
|
||||
return Exception\OAuth\UnsupportedGrantTypeException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
|
||||
case 'unsupported_response_type':
|
||||
return Exception\OAuth\UnsupportedResponseTypeException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
|
||||
default:
|
||||
return Exception\OAuth\UnknownOAuthErrorException::factory($description, $rcode, $rbody, $resp, $rheaders, $errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param null|array $appInfo
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
private static function _formatAppInfo($appInfo)
|
||||
{
|
||||
if ($appInfo !== null) {
|
||||
$string = $appInfo['name'];
|
||||
if ($appInfo['version'] !== null) {
|
||||
$string .= '/' . $appInfo['version'];
|
||||
}
|
||||
if ($appInfo['url'] !== null) {
|
||||
$string .= ' (' . $appInfo['url'] . ')';
|
||||
}
|
||||
return $string;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param string $apiKey
|
||||
* @param null $clientInfo
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _defaultHeaders($apiKey, $clientInfo = null)
|
||||
{
|
||||
$uaString = 'Stripe/v1 PhpBindings/' . Stripe::VERSION;
|
||||
|
||||
$langVersion = phpversion();
|
||||
$uname = php_uname();
|
||||
|
||||
$appInfo = Stripe::getAppInfo();
|
||||
$ua = [
|
||||
'bindings_version' => Stripe::VERSION,
|
||||
'lang' => 'php',
|
||||
'lang_version' => $langVersion,
|
||||
'publisher' => 'stripe',
|
||||
'uname' => $uname,
|
||||
];
|
||||
if ($clientInfo) {
|
||||
$ua = array_merge($clientInfo, $ua);
|
||||
}
|
||||
if ($appInfo !== null) {
|
||||
$uaString .= ' ' . self::_formatAppInfo($appInfo);
|
||||
$ua['application'] = $appInfo;
|
||||
}
|
||||
|
||||
$defaultHeaders = [
|
||||
'X-Stripe-Client-User-Agent' => json_encode($ua),
|
||||
'User-Agent' => $uaString,
|
||||
'Authorization' => 'Bearer ' . $apiKey,
|
||||
];
|
||||
return $defaultHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception\AuthenticationException
|
||||
* @throws Exception\ApiConnectionException
|
||||
*/
|
||||
private function _requestRaw($method, $url, $params, $headers)
|
||||
{
|
||||
$myApiKey = $this->_apiKey;
|
||||
if (!$myApiKey) {
|
||||
$myApiKey = Stripe::$apiKey;
|
||||
}
|
||||
|
||||
if (!$myApiKey) {
|
||||
$msg = 'No API key provided. (HINT: set your API key using '
|
||||
. '"Stripe::setApiKey(<API-KEY>)". You can generate API keys from '
|
||||
. 'the Stripe web interface. See https://stripe.com/api for '
|
||||
. 'details, or email support@stripe.com if you have any questions.';
|
||||
throw new Exception\AuthenticationException($msg);
|
||||
}
|
||||
|
||||
// Clients can supply arbitrary additional keys to be included in the
|
||||
// X-Stripe-Client-User-Agent header via the optional getUserAgentInfo()
|
||||
// method
|
||||
$clientUAInfo = null;
|
||||
if (method_exists($this->httpClient(), 'getUserAgentInfo')) {
|
||||
$clientUAInfo = $this->httpClient()->getUserAgentInfo();
|
||||
}
|
||||
|
||||
$absUrl = $this->_apiBase.$url;
|
||||
$params = self::_encodeObjects($params);
|
||||
$defaultHeaders = $this->_defaultHeaders($myApiKey, $clientUAInfo);
|
||||
if (Stripe::$apiVersion) {
|
||||
$defaultHeaders['Stripe-Version'] = Stripe::$apiVersion;
|
||||
}
|
||||
|
||||
if (Stripe::$accountId) {
|
||||
$defaultHeaders['Stripe-Account'] = Stripe::$accountId;
|
||||
}
|
||||
|
||||
if (Stripe::$enableTelemetry && self::$requestTelemetry != null) {
|
||||
$defaultHeaders["X-Stripe-Client-Telemetry"] = self::_telemetryJson(self::$requestTelemetry);
|
||||
}
|
||||
|
||||
$hasFile = false;
|
||||
foreach ($params as $k => $v) {
|
||||
if (is_resource($v)) {
|
||||
$hasFile = true;
|
||||
$params[$k] = self::_processResourceParam($v);
|
||||
} elseif ($v instanceof \CURLFile) {
|
||||
$hasFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasFile) {
|
||||
$defaultHeaders['Content-Type'] = 'multipart/form-data';
|
||||
} else {
|
||||
$defaultHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
}
|
||||
|
||||
$combinedHeaders = array_merge($defaultHeaders, $headers);
|
||||
$rawHeaders = [];
|
||||
|
||||
foreach ($combinedHeaders as $header => $value) {
|
||||
$rawHeaders[] = $header . ': ' . $value;
|
||||
}
|
||||
|
||||
$requestStartMs = Util\Util::currentTimeMillis();
|
||||
|
||||
list($rbody, $rcode, $rheaders) = $this->httpClient()->request(
|
||||
$method,
|
||||
$absUrl,
|
||||
$rawHeaders,
|
||||
$params,
|
||||
$hasFile
|
||||
);
|
||||
|
||||
if (isset($rheaders['request-id'])) {
|
||||
self::$requestTelemetry = new RequestTelemetry(
|
||||
$rheaders['request-id'],
|
||||
Util\Util::currentTimeMillis() - $requestStartMs
|
||||
);
|
||||
}
|
||||
|
||||
return [$rbody, $rcode, $rheaders, $myApiKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $resource
|
||||
*
|
||||
* @return \CURLFile|string
|
||||
*
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
private function _processResourceParam($resource)
|
||||
{
|
||||
if (get_resource_type($resource) !== 'stream') {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'Attempted to upload a resource that is not a stream'
|
||||
);
|
||||
}
|
||||
|
||||
$metaData = stream_get_meta_data($resource);
|
||||
if ($metaData['wrapper_type'] !== 'plainfile') {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'Only plainfile resource streams are supported'
|
||||
);
|
||||
}
|
||||
|
||||
// We don't have the filename or mimetype, but the API doesn't care
|
||||
return new \CURLFile($metaData['uri']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rbody
|
||||
* @param int $rcode
|
||||
* @param array $rheaders
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception\UnexpectedValueException
|
||||
* @throws Exception\ApiErrorException
|
||||
*/
|
||||
private function _interpretResponse($rbody, $rcode, $rheaders)
|
||||
{
|
||||
$resp = json_decode($rbody, true);
|
||||
$jsonError = json_last_error();
|
||||
if ($resp === null && $jsonError !== JSON_ERROR_NONE) {
|
||||
$msg = "Invalid response body from API: $rbody "
|
||||
. "(HTTP response code was $rcode, json_last_error() was $jsonError)";
|
||||
throw new Exception\UnexpectedValueException($msg, $rcode, $rbody);
|
||||
}
|
||||
|
||||
if ($rcode < 200 || $rcode >= 300) {
|
||||
$this->handleErrorResponse($rbody, $rcode, $rheaders, $resp);
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param HttpClient\ClientInterface $client
|
||||
*/
|
||||
public static function setHttpClient($client)
|
||||
{
|
||||
self::$_httpClient = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* Resets any stateful telemetry data
|
||||
*/
|
||||
public static function resetTelemetry()
|
||||
{
|
||||
self::$requestTelemetry = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpClient\ClientInterface
|
||||
*/
|
||||
private function httpClient()
|
||||
{
|
||||
if (!self::$_httpClient) {
|
||||
self::$_httpClient = HttpClient\CurlClient::instance();
|
||||
}
|
||||
return self::$_httpClient;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class ApiResource
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
abstract class ApiResource extends StripeObject
|
||||
{
|
||||
use ApiOperations\Request;
|
||||
|
||||
/**
|
||||
* @return \Stripe\Util\Set A list of fields that can be their own type of
|
||||
* API resource (say a nested card under an account for example), and if
|
||||
* that resource is set, it should be transmitted to the API on a create or
|
||||
* update. Doing so is not the default behavior because API resources
|
||||
* should normally be persisted on their own RESTful endpoints.
|
||||
*/
|
||||
public static function getSavedNestedResources()
|
||||
{
|
||||
static $savedNestedResources = null;
|
||||
if ($savedNestedResources === null) {
|
||||
$savedNestedResources = new Util\Set();
|
||||
}
|
||||
return $savedNestedResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var boolean A flag that can be set a behavior that will cause this
|
||||
* resource to be encoded and sent up along with an update of its parent
|
||||
* resource. This is usually not desirable because resources are updated
|
||||
* individually on their own endpoints, but there are certain cases,
|
||||
* replacing a customer's source for example, where this is allowed.
|
||||
*/
|
||||
public $saveWithParent = false;
|
||||
|
||||
public function __set($k, $v)
|
||||
{
|
||||
parent::__set($k, $v);
|
||||
$v = $this->$k;
|
||||
if ((static::getSavedNestedResources()->includes($k)) &&
|
||||
($v instanceof ApiResource)) {
|
||||
$v->saveWithParent = true;
|
||||
}
|
||||
return $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ApiResource The refreshed resource.
|
||||
*
|
||||
* @throws Exception\ApiErrorException
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
$requestor = new ApiRequestor($this->_opts->apiKey, static::baseUrl());
|
||||
$url = $this->instanceUrl();
|
||||
|
||||
list($response, $this->_opts->apiKey) = $requestor->request(
|
||||
'get',
|
||||
$url,
|
||||
$this->_retrieveOptions,
|
||||
$this->_opts->headers
|
||||
);
|
||||
$this->setLastResponse($response);
|
||||
$this->refreshFrom($response->json, $this->_opts);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The base URL for the given class.
|
||||
*/
|
||||
public static function baseUrl()
|
||||
{
|
||||
return Stripe::$apiBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The endpoint URL for the given class.
|
||||
*/
|
||||
public static function classUrl()
|
||||
{
|
||||
// Replace dots with slashes for namespaced resources, e.g. if the object's name is
|
||||
// "foo.bar", then its URL will be "/v1/foo/bars".
|
||||
$base = str_replace('.', '/', static::OBJECT_NAME);
|
||||
return "/v1/${base}s";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The instance endpoint URL for the given class.
|
||||
*/
|
||||
public static function resourceUrl($id)
|
||||
{
|
||||
if ($id === null) {
|
||||
$class = get_called_class();
|
||||
$message = "Could not determine which URL to request: "
|
||||
. "$class instance has invalid ID: $id";
|
||||
throw new Exception\UnexpectedValueException($message);
|
||||
}
|
||||
$id = Util\Util::utf8($id);
|
||||
$base = static::classUrl();
|
||||
$extn = urlencode($id);
|
||||
return "$base/$extn";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The full API URL for this API resource.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
return static::resourceUrl($this['id']);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
use Stripe\Util\CaseInsensitiveArray;
|
||||
|
||||
/**
|
||||
* Class ApiResponse
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class ApiResponse
|
||||
{
|
||||
public $headers;
|
||||
public $body;
|
||||
public $json;
|
||||
public $code;
|
||||
|
||||
/**
|
||||
* @param string $body
|
||||
* @param integer $code
|
||||
* @param array|CaseInsensitiveArray|null $headers
|
||||
* @param array|null $json
|
||||
*/
|
||||
public function __construct($body, $code, $headers, $json)
|
||||
{
|
||||
$this->body = $body;
|
||||
$this->code = $code;
|
||||
$this->headers = $headers;
|
||||
$this->json = $json;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class ApplePayDomain
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class ApplePayDomain extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "apple_pay_domain";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Create;
|
||||
use ApiOperations\Delete;
|
||||
use ApiOperations\Retrieve;
|
||||
|
||||
/**
|
||||
* @return string The class URL for this resource. It needs to be special
|
||||
* cased because it doesn't fit into the standard resource pattern.
|
||||
*/
|
||||
public static function classUrl()
|
||||
{
|
||||
return '/v1/apple_pay/domains';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class ApplicationFee
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property string $account
|
||||
* @property int $amount
|
||||
* @property int $amount_refunded
|
||||
* @property string $application
|
||||
* @property string $balance_transaction
|
||||
* @property string $charge
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property bool $livemode
|
||||
* @property string $originating_transaction
|
||||
* @property bool $refunded
|
||||
* @property Collection $refunds
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class ApplicationFee extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "application_fee";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\NestedResource;
|
||||
use ApiOperations\Retrieve;
|
||||
|
||||
const PATH_REFUNDS = '/refunds';
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the application fee on which to create the refund.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApplicationFeeRefund
|
||||
*/
|
||||
public static function createRefund($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_createNestedResource($id, static::PATH_REFUNDS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the application fee to which the refund belongs.
|
||||
* @param array|null $refundId The ID of the refund to retrieve.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApplicationFeeRefund
|
||||
*/
|
||||
public static function retrieveRefund($id, $refundId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_retrieveNestedResource($id, static::PATH_REFUNDS, $refundId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the application fee to which the refund belongs.
|
||||
* @param array|null $refundId The ID of the refund to update.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApplicationFeeRefund
|
||||
*/
|
||||
public static function updateRefund($id, $refundId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_updateNestedResource($id, static::PATH_REFUNDS, $refundId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the application fee on which to retrieve the refunds.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of refunds.
|
||||
*/
|
||||
public static function allRefunds($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_allNestedResources($id, static::PATH_REFUNDS, $params, $opts);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class ApplicationFeeRefund
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $amount
|
||||
* @property string $balance_transaction
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property string $fee
|
||||
* @property StripeObject $metadata
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class ApplicationFeeRefund extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "fee_refund";
|
||||
|
||||
use ApiOperations\Update {
|
||||
save as protected _save;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The API URL for this Stripe refund.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
$id = $this['id'];
|
||||
$fee = $this['fee'];
|
||||
if (!$id) {
|
||||
throw new Exception\UnexpectedValueException(
|
||||
"Could not determine which URL to request: " .
|
||||
"class instance has invalid ID: $id",
|
||||
null
|
||||
);
|
||||
}
|
||||
$id = Util\Util::utf8($id);
|
||||
$fee = Util\Util::utf8($fee);
|
||||
|
||||
$base = ApplicationFee::classUrl();
|
||||
$feeExtn = urlencode($fee);
|
||||
$extn = urlencode($id);
|
||||
return "$base/$feeExtn/refunds/$extn";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @return ApplicationFeeRefund The saved refund.
|
||||
*/
|
||||
public function save($opts = null)
|
||||
{
|
||||
return $this->_save($opts);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Balance
|
||||
*
|
||||
* @property string $object
|
||||
* @property array $available
|
||||
* @property array $connect_reserved
|
||||
* @property bool $livemode
|
||||
* @property array $pending
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Balance extends SingletonApiResource
|
||||
{
|
||||
const OBJECT_NAME = "balance";
|
||||
|
||||
/**
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Balance
|
||||
*/
|
||||
public static function retrieve($opts = null)
|
||||
{
|
||||
return self::_singletonRetrieve($opts);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class BalanceTransaction
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $amount
|
||||
* @property int $available_on
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property string $description
|
||||
* @property float $exchange_rate
|
||||
* @property int $fee
|
||||
* @property mixed $fee_details
|
||||
* @property int $net
|
||||
* @property string $source
|
||||
* @property string $status
|
||||
* @property string $type
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class BalanceTransaction extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "balance_transaction";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Retrieve;
|
||||
|
||||
/**
|
||||
* Possible string representations of the type of balance transaction.
|
||||
* @link https://stripe.com/docs/api/balance/balance_transaction#balance_transaction_object-type
|
||||
*/
|
||||
const TYPE_ADJUSTMENT = 'adjustment';
|
||||
const TYPE_ADVANCE = 'advance';
|
||||
const TYPE_ADVANCE_FUNDING = 'advance_funding';
|
||||
const TYPE_APPLICATION_FEE = 'application_fee';
|
||||
const TYPE_APPLICATION_FEE_REFUND = 'application_fee_refund';
|
||||
const TYPE_CHARGE = 'charge';
|
||||
const TYPE_CONNECT_COLLECTION_TRANSFER = 'connect_collection_transfer';
|
||||
const TYPE_ISSUING_AUTHORIZATION_HOLD = 'issuing_authorization_hold';
|
||||
const TYPE_ISSUING_AUTHORIZATION_RELEASE = 'issuing_authorization_release';
|
||||
const TYPE_ISSUING_TRANSACTION = 'issuing_transaction';
|
||||
const TYPE_PAYMENT = 'payment';
|
||||
const TYPE_PAYMENT_FAILURE_REFUND = 'payment_failure_refund';
|
||||
const TYPE_PAYMENT_REFUND = 'payment_refund';
|
||||
const TYPE_PAYOUT = 'payout';
|
||||
const TYPE_PAYOUT_CANCEL = 'payout_cancel';
|
||||
const TYPE_PAYOUT_FAILURE = 'payout_failure';
|
||||
const TYPE_REFUND = 'refund';
|
||||
const TYPE_REFUND_FAILURE = 'refund_failure';
|
||||
const TYPE_RESERVE_TRANSACTION = 'reserve_transaction';
|
||||
const TYPE_RESERVED_FUNDS = 'reserved_funds';
|
||||
const TYPE_STRIPE_FEE = 'stripe_fee';
|
||||
const TYPE_STRIPE_FX_FEE = 'stripe_fx_fee';
|
||||
const TYPE_TAX_FEE = 'tax_fee';
|
||||
const TYPE_TOPUP = 'topup';
|
||||
const TYPE_TOPUP_REVERSAL = 'topup_reversal';
|
||||
const TYPE_TRANSFER = 'transfer';
|
||||
const TYPE_TRANSFER_CANCEL = 'transfer_cancel';
|
||||
const TYPE_TRANSFER_FAILURE = 'transfer_failure';
|
||||
const TYPE_TRANSFER_REFUND = 'transfer_refund';
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class BankAccount
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property string $account
|
||||
* @property string $account_holder_name
|
||||
* @property string $account_holder_type
|
||||
* @property string $bank_name
|
||||
* @property string $country
|
||||
* @property string $currency
|
||||
* @property string $customer
|
||||
* @property bool $default_for_currency
|
||||
* @property string $fingerprint
|
||||
* @property string $last4
|
||||
* @property StripeObject $metadata
|
||||
* @property string $routing_number
|
||||
* @property string $status
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class BankAccount extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "bank_account";
|
||||
|
||||
use ApiOperations\Delete;
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of the bank verification status.
|
||||
* @link https://stripe.com/docs/api/external_account_bank_accounts/object#account_bank_account_object-status
|
||||
*/
|
||||
const STATUS_NEW = 'new';
|
||||
const STATUS_VALIDATED = 'validated';
|
||||
const STATUS_VERIFIED = 'verified';
|
||||
const STATUS_VERIFICATION_FAILED = 'verification_failed';
|
||||
const STATUS_ERRORED = 'errored';
|
||||
|
||||
/**
|
||||
* @return string The instance URL for this resource. It needs to be special
|
||||
* cased because it doesn't fit into the standard resource pattern.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
if ($this['customer']) {
|
||||
$base = Customer::classUrl();
|
||||
$parent = $this['customer'];
|
||||
$path = 'sources';
|
||||
} elseif ($this['account']) {
|
||||
$base = Account::classUrl();
|
||||
$parent = $this['account'];
|
||||
$path = 'external_accounts';
|
||||
} else {
|
||||
$msg = "Bank accounts cannot be accessed without a customer ID or account ID.";
|
||||
throw new Exception\UnexpectedValueException($msg, null);
|
||||
}
|
||||
$parentExtn = urlencode(Util\Util::utf8($parent));
|
||||
$extn = urlencode(Util\Util::utf8($this['id']));
|
||||
return "$base/$parentExtn/$path/$extn";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $_id
|
||||
* @param array|string|null $_opts
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function retrieve($_id, $_opts = null)
|
||||
{
|
||||
$msg = "Bank accounts cannot be retrieved without a customer ID or " .
|
||||
"an account ID. Retrieve a bank account using " .
|
||||
"`Customer::retrieveSource('customer_id', " .
|
||||
"'bank_account_id')` or `Account::retrieveExternalAccount(" .
|
||||
"'account_id', 'bank_account_id')`.";
|
||||
throw new Exception\BadMethodCallException($msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $_id
|
||||
* @param array|null $_params
|
||||
* @param array|string|null $_options
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function update($_id, $_params = null, $_options = null)
|
||||
{
|
||||
$msg = "Bank accounts cannot be updated without a customer ID or an " .
|
||||
"account ID. Update a bank account using " .
|
||||
"`Customer::updateSource('customer_id', 'bank_account_id', " .
|
||||
"\$updateParams)` or `Account::updateExternalAccount(" .
|
||||
"'account_id', 'bank_account_id', \$updateParams)`.";
|
||||
throw new Exception\BadMethodCallException($msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return BankAccount The verified bank account.
|
||||
*/
|
||||
public function verify($params = null, $options = null)
|
||||
{
|
||||
$url = $this->instanceUrl() . '/verify';
|
||||
list($response, $opts) = $this->_request('post', $url, $params, $options);
|
||||
$this->refreshFrom($response, $opts);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class BitcoinReceiver
|
||||
*
|
||||
* @package Stripe
|
||||
*
|
||||
* @deprecated Bitcoin receivers are deprecated. Please use the sources API instead.
|
||||
* @link https://stripe.com/docs/sources/bitcoin
|
||||
*/
|
||||
class BitcoinReceiver extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "bitcoin_receiver";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Retrieve;
|
||||
|
||||
/**
|
||||
* @return string The class URL for this resource. It needs to be special
|
||||
* cased because it doesn't fit into the standard resource pattern.
|
||||
*/
|
||||
public static function classUrl()
|
||||
{
|
||||
return "/v1/bitcoin/receivers";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The instance URL for this resource. It needs to be special
|
||||
* cased because it doesn't fit into the standard resource pattern.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
if ($this['customer']) {
|
||||
$base = Customer::classUrl();
|
||||
$parent = $this['customer'];
|
||||
$path = 'sources';
|
||||
$parentExtn = urlencode(Util\Util::utf8($parent));
|
||||
$extn = urlencode(Util\Util::utf8($this['id']));
|
||||
return "$base/$parentExtn/$path/$extn";
|
||||
} else {
|
||||
$base = BitcoinReceiver::classUrl();
|
||||
$extn = urlencode(Util\Util::utf8($this['id']));
|
||||
return "$base/$extn";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class BitcoinTransaction
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class BitcoinTransaction extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "bitcoin_transaction";
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Capability
|
||||
*
|
||||
* @package Stripe
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property string $account
|
||||
* @property bool $requested
|
||||
* @property int $requested_at
|
||||
* @property mixed $requirements
|
||||
* @property string $status
|
||||
*/
|
||||
class Capability extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "capability";
|
||||
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of a capability's status.
|
||||
* @link https://stripe.com/docs/api/capabilities/object#capability_object-status
|
||||
*/
|
||||
const STATUS_ACTIVE = 'active';
|
||||
const STATUS_INACTIVE = 'inactive';
|
||||
const STATUS_PENDING = 'pending';
|
||||
const STATUS_UNREQUESTED = 'unrequested';
|
||||
|
||||
/**
|
||||
* @return string The API URL for this Stripe account reversal.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
$id = $this['id'];
|
||||
$account = $this['account'];
|
||||
if (!$id) {
|
||||
throw new Exception\UnexpectedValueException(
|
||||
"Could not determine which URL to request: " .
|
||||
"class instance has invalid ID: $id",
|
||||
null
|
||||
);
|
||||
}
|
||||
$id = Util\Util::utf8($id);
|
||||
$account = Util\Util::utf8($account);
|
||||
|
||||
$base = Account::classUrl();
|
||||
$accountExtn = urlencode($account);
|
||||
$extn = urlencode($id);
|
||||
return "$base/$accountExtn/capabilities/$extn";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $_id
|
||||
* @param array|string|null $_opts
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function retrieve($_id, $_opts = null)
|
||||
{
|
||||
$msg = "Capabilities cannot be retrieved without an account ID. " .
|
||||
"Retrieve a capability using `Account::retrieveCapability(" .
|
||||
"'account_id', 'capability_id')`.";
|
||||
throw new Exception\BadMethodCallException($msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $_id
|
||||
* @param array|null $_params
|
||||
* @param array|string|null $_options
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function update($_id, $_params = null, $_options = null)
|
||||
{
|
||||
$msg = "Capabilities cannot be updated without an account ID. " .
|
||||
"Update a capability using `Account::updateCapability(" .
|
||||
"'account_id', 'capability_id', \$updateParams)`.";
|
||||
throw new Exception\BadMethodCallException($msg, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Card
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property string $account
|
||||
* @property string $address_city
|
||||
* @property string $address_country
|
||||
* @property string $address_line1
|
||||
* @property string $address_line1_check
|
||||
* @property string $address_line2
|
||||
* @property string $address_state
|
||||
* @property string $address_zip
|
||||
* @property string $address_zip_check
|
||||
* @property string[] $available_payout_methods
|
||||
* @property string $brand
|
||||
* @property string $country
|
||||
* @property string $currency
|
||||
* @property string $customer
|
||||
* @property string $cvc_check
|
||||
* @property bool $default_for_currency
|
||||
* @property string $dynamic_last4
|
||||
* @property int $exp_month
|
||||
* @property int $exp_year
|
||||
* @property string $fingerprint
|
||||
* @property string $funding
|
||||
* @property string $last4
|
||||
* @property StripeObject $metadata
|
||||
* @property string $name
|
||||
* @property string $recipient
|
||||
* @property string $tokenization_method
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Card extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "card";
|
||||
|
||||
use ApiOperations\Delete;
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of the CVC check status.
|
||||
* @link https://stripe.com/docs/api/cards/object#card_object-cvc_check
|
||||
*/
|
||||
const CVC_CHECK_FAIL = 'fail';
|
||||
const CVC_CHECK_PASS = 'pass';
|
||||
const CVC_CHECK_UNAVAILABLE = 'unavailable';
|
||||
const CVC_CHECK_UNCHECKED = 'unchecked';
|
||||
|
||||
/**
|
||||
* Possible string representations of the funding of the card.
|
||||
* @link https://stripe.com/docs/api/cards/object#card_object-funding
|
||||
*/
|
||||
const FUNDING_CREDIT = 'credit';
|
||||
const FUNDING_DEBIT = 'debit';
|
||||
const FUNDING_PREPAID = 'prepaid';
|
||||
const FUNDING_UNKNOWN = 'unknown';
|
||||
|
||||
/**
|
||||
* Possible string representations of the tokenization method when using Apple Pay or Google Pay.
|
||||
* @link https://stripe.com/docs/api/cards/object#card_object-tokenization_method
|
||||
*/
|
||||
const TOKENIZATION_METHOD_APPLE_PAY = 'apple_pay';
|
||||
const TOKENIZATION_METHOD_GOOGLE_PAY = 'google_pay';
|
||||
|
||||
/**
|
||||
* @return string The instance URL for this resource. It needs to be special
|
||||
* cased because cards are nested resources that may belong to different
|
||||
* top-level resources.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
if ($this['customer']) {
|
||||
$base = Customer::classUrl();
|
||||
$parent = $this['customer'];
|
||||
$path = 'sources';
|
||||
} elseif ($this['account']) {
|
||||
$base = Account::classUrl();
|
||||
$parent = $this['account'];
|
||||
$path = 'external_accounts';
|
||||
} elseif ($this['recipient']) {
|
||||
$base = Recipient::classUrl();
|
||||
$parent = $this['recipient'];
|
||||
$path = 'cards';
|
||||
} else {
|
||||
$msg = "Cards cannot be accessed without a customer ID, account ID or recipient ID.";
|
||||
throw new Exception\UnexpectedValueException($msg);
|
||||
}
|
||||
$parentExtn = urlencode(Util\Util::utf8($parent));
|
||||
$extn = urlencode(Util\Util::utf8($this['id']));
|
||||
return "$base/$parentExtn/$path/$extn";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $_id
|
||||
* @param array|string|null $_opts
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function retrieve($_id, $_opts = null)
|
||||
{
|
||||
$msg = "Cards cannot be retrieved without a customer ID or an " .
|
||||
"account ID. Retrieve a card using " .
|
||||
"`Customer::retrieveSource('customer_id', 'card_id')` or " .
|
||||
"`Account::retrieveExternalAccount('account_id', 'card_id')`.";
|
||||
throw new Exception\BadMethodCallException($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $_id
|
||||
* @param array|null $_params
|
||||
* @param array|string|null $_options
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function update($_id, $_params = null, $_options = null)
|
||||
{
|
||||
$msg = "Cards cannot be updated without a customer ID or an " .
|
||||
"account ID. Update a card using " .
|
||||
"`Customer::updateSource('customer_id', 'card_id', " .
|
||||
"\$updateParams)` or `Account::updateExternalAccount(" .
|
||||
"'account_id', 'card_id', \$updateParams)`.";
|
||||
throw new Exception\BadMethodCallException($msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Charge
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $amount
|
||||
* @property int $amount_refunded
|
||||
* @property string $application
|
||||
* @property string $application_fee
|
||||
* @property int $application_fee_amount
|
||||
* @property string $balance_transaction
|
||||
* @property mixed $billing_details
|
||||
* @property bool $captured
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property string $customer
|
||||
* @property string $description
|
||||
* @property string $destination
|
||||
* @property string $dispute
|
||||
* @property string $failure_code
|
||||
* @property string $failure_message
|
||||
* @property mixed $fraud_details
|
||||
* @property string $invoice
|
||||
* @property bool $livemode
|
||||
* @property StripeObject $metadata
|
||||
* @property string $on_behalf_of
|
||||
* @property string $order
|
||||
* @property mixed $outcome
|
||||
* @property bool $paid
|
||||
* @property string $payment_intent
|
||||
* @property string $payment_method
|
||||
* @property mixed $payment_method_details
|
||||
* @property string $receipt_email
|
||||
* @property string $receipt_number
|
||||
* @property string $receipt_url
|
||||
* @property bool $refunded
|
||||
* @property Collection $refunds
|
||||
* @property string $review
|
||||
* @property mixed $shipping
|
||||
* @property mixed $source
|
||||
* @property string $source_transfer
|
||||
* @property string $statement_descriptor
|
||||
* @property string $status
|
||||
* @property string $transfer
|
||||
* @property mixed $transfer_data
|
||||
* @property string $transfer_group
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Charge extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "charge";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Create;
|
||||
use ApiOperations\Retrieve;
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of decline codes.
|
||||
* These strings are applicable to the decline_code property of the \Stripe\Exception\CardException exception.
|
||||
* @link https://stripe.com/docs/declines/codes
|
||||
*/
|
||||
const DECLINED_APPROVE_WITH_ID = 'approve_with_id';
|
||||
const DECLINED_CALL_ISSUER = 'call_issuer';
|
||||
const DECLINED_CARD_NOT_SUPPORTED = 'card_not_supported';
|
||||
const DECLINED_CARD_VELOCITY_EXCEEDED = 'card_velocity_exceeded';
|
||||
const DECLINED_CURRENCY_NOT_SUPPORTED = 'currency_not_supported';
|
||||
const DECLINED_DO_NOT_HONOR = 'do_not_honor';
|
||||
const DECLINED_DO_NOT_TRY_AGAIN = 'do_not_try_again';
|
||||
const DECLINED_DUPLICATED_TRANSACTION = 'duplicate_transaction';
|
||||
const DECLINED_EXPIRED_CARD = 'expired_card';
|
||||
const DECLINED_FRAUDULENT = 'fraudulent';
|
||||
const DECLINED_GENERIC_DECLINE = 'generic_decline';
|
||||
const DECLINED_INCORRECT_NUMBER = 'incorrect_number';
|
||||
const DECLINED_INCORRECT_CVC = 'incorrect_cvc';
|
||||
const DECLINED_INCORRECT_PIN = 'incorrect_pin';
|
||||
const DECLINED_INCORRECT_ZIP = 'incorrect_zip';
|
||||
const DECLINED_INSUFFICIENT_FUNDS = 'insufficient_funds';
|
||||
const DECLINED_INVALID_ACCOUNT = 'invalid_account';
|
||||
const DECLINED_INVALID_AMOUNT = 'invalid_amount';
|
||||
const DECLINED_INVALID_CVC = 'invalid_cvc';
|
||||
const DECLINED_INVALID_EXPIRY_YEAR = 'invalid_expiry_year';
|
||||
const DECLINED_INVALID_NUMBER = 'invalid_number';
|
||||
const DECLINED_INVALID_PIN = 'invalid_pin';
|
||||
const DECLINED_ISSUER_NOT_AVAILABLE = 'issuer_not_available';
|
||||
const DECLINED_LOST_CARD = 'lost_card';
|
||||
const DECLINED_MERCHANT_BLACKLIST = 'merchant_blacklist';
|
||||
const DECLINED_NEW_ACCOUNT_INFORMATION_AVAILABLE = 'new_account_information_available';
|
||||
const DECLINED_NO_ACTION_TAKEN = 'no_action_taken';
|
||||
const DECLINED_NOT_PERMITTED = 'not_permitted';
|
||||
const DECLINED_PICKUP_CARD = 'pickup_card';
|
||||
const DECLINED_PIN_TRY_EXCEEDED = 'pin_try_exceeded';
|
||||
const DECLINED_PROCESSING_ERROR = 'processing_error';
|
||||
const DECLINED_REENTER_TRANSACTION = 'reenter_transaction';
|
||||
const DECLINED_RESTRICTED_CARD = 'restricted_card';
|
||||
const DECLINED_REVOCATION_OF_ALL_AUTHORIZATIONS = 'revocation_of_all_authorizations';
|
||||
const DECLINED_REVOCATION_OF_AUTHORIZATION = 'revocation_of_authorization';
|
||||
const DECLINED_SECURITY_VIOLATION = 'security_violation';
|
||||
const DECLINED_SERVICE_NOT_ALLOWED = 'service_not_allowed';
|
||||
const DECLINED_STOLEN_CARD = 'stolen_card';
|
||||
const DECLINED_STOP_PAYMENT_ORDER = 'stop_payment_order';
|
||||
const DECLINED_TESTMODE_DECLINE = 'testmode_decline';
|
||||
const DECLINED_TRANSACTION_NOT_ALLOWED = 'transaction_not_allowed';
|
||||
const DECLINED_TRY_AGAIN_LATER = 'try_again_later';
|
||||
const DECLINED_WITHDRAWAL_COUNT_LIMIT_EXCEEDED = 'withdrawal_count_limit_exceeded';
|
||||
|
||||
/**
|
||||
* Possible string representations of the status of the charge.
|
||||
* @link https://stripe.com/docs/api/charges/object#charge_object-status
|
||||
*/
|
||||
const STATUS_FAILED = 'failed';
|
||||
const STATUS_PENDING = 'pending';
|
||||
const STATUS_SUCCEEDED = 'succeeded';
|
||||
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Charge The captured charge.
|
||||
*/
|
||||
public function capture($params = null, $options = null)
|
||||
{
|
||||
$url = $this->instanceUrl() . '/capture';
|
||||
list($response, $opts) = $this->_request('post', $url, $params, $options);
|
||||
$this->refreshFrom($response, $opts);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Checkout;
|
||||
|
||||
/**
|
||||
* Class Session
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property string $cancel_url
|
||||
* @property string $client_reference_id
|
||||
* @property string $customer
|
||||
* @property string $customer_email
|
||||
* @property mixed $display_items
|
||||
* @property bool $livemode
|
||||
* @property string $payment_intent
|
||||
* @property string[] $payment_method_types
|
||||
* @property string $submit_type
|
||||
* @property string $subscription
|
||||
* @property string $success_url
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Session extends \Stripe\ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "checkout.session";
|
||||
|
||||
use \Stripe\ApiOperations\Create;
|
||||
use \Stripe\ApiOperations\Retrieve;
|
||||
|
||||
/**
|
||||
* Possible string representations of submit type.
|
||||
* @link https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-submit_type
|
||||
*/
|
||||
const SUBMIT_TYPE_AUTO = 'auto';
|
||||
const SUBMIT_TYPE_BOOK = 'book';
|
||||
const SUBMIT_TYPE_DONATE = 'donate';
|
||||
const SUBMIT_TYPE_PAY = 'pay';
|
||||
}
|
||||
|
|
@ -0,0 +1,229 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Collection
|
||||
*
|
||||
* @property string $object
|
||||
* @property string $url
|
||||
* @property bool $has_more
|
||||
* @property mixed $data
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Collection extends StripeObject implements \IteratorAggregate
|
||||
{
|
||||
const OBJECT_NAME = "list";
|
||||
|
||||
use ApiOperations\Request;
|
||||
|
||||
protected $filters = [];
|
||||
|
||||
/**
|
||||
* @return string The base URL for the given class.
|
||||
*/
|
||||
public static function baseUrl()
|
||||
{
|
||||
return Stripe::$apiBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filters.
|
||||
*
|
||||
* @return array The filters.
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filters, removing paging options.
|
||||
*
|
||||
* @param array $filters The filters.
|
||||
*/
|
||||
public function setFilters($filters)
|
||||
{
|
||||
$this->filters = $filters;
|
||||
unset($this->filters['starting_after']);
|
||||
unset($this->filters['ending_before']);
|
||||
}
|
||||
|
||||
public function offsetGet($k)
|
||||
{
|
||||
if (is_string($k)) {
|
||||
return parent::offsetGet($k);
|
||||
} else {
|
||||
$msg = "You tried to access the {$k} index, but Collection " .
|
||||
"types only support string keys. (HINT: List calls " .
|
||||
"return an object with a `data` (which is the data " .
|
||||
"array). You likely want to call ->data[{$k}])";
|
||||
throw new Exception\InvalidArgumentException($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function all($params = null, $opts = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
list($url, $params) = $this->extractPathAndUpdateParams($params);
|
||||
|
||||
list($response, $opts) = $this->_request('get', $url, $params, $opts);
|
||||
$obj = Util\Util::convertToStripeObject($response, $opts);
|
||||
if (!($obj instanceof \Stripe\Collection)) {
|
||||
throw new \Stripe\Exception\UnexpectedValueException(
|
||||
'Expected type ' . \Stripe\Collection::class . ', got "' . get_class($obj) . '" instead.'
|
||||
);
|
||||
}
|
||||
$obj->setFilters($params);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function create($params = null, $opts = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
list($url, $params) = $this->extractPathAndUpdateParams($params);
|
||||
|
||||
list($response, $opts) = $this->_request('post', $url, $params, $opts);
|
||||
return Util\Util::convertToStripeObject($response, $opts);
|
||||
}
|
||||
|
||||
public function retrieve($id, $params = null, $opts = null)
|
||||
{
|
||||
self::_validateParams($params);
|
||||
list($url, $params) = $this->extractPathAndUpdateParams($params);
|
||||
|
||||
$id = Util\Util::utf8($id);
|
||||
$extn = urlencode($id);
|
||||
list($response, $opts) = $this->_request(
|
||||
'get',
|
||||
"$url/$extn",
|
||||
$params,
|
||||
$opts
|
||||
);
|
||||
return Util\Util::convertToStripeObject($response, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \ArrayIterator An iterator that can be used to iterate
|
||||
* across objects in the current page.
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Generator|StripeObject[] A generator that can be used to
|
||||
* iterate across all objects across all pages. As page boundaries are
|
||||
* encountered, the next page will be fetched automatically for
|
||||
* continued iteration.
|
||||
*/
|
||||
public function autoPagingIterator()
|
||||
{
|
||||
$page = $this;
|
||||
|
||||
while (true) {
|
||||
foreach ($page as $item) {
|
||||
yield $item;
|
||||
}
|
||||
|
||||
$page = $page->nextPage();
|
||||
|
||||
if ($page->isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty collection. This is returned from {@see nextPage()}
|
||||
* when we know that there isn't a next page in order to replicate the
|
||||
* behavior of the API when it attempts to return a page beyond the last.
|
||||
*
|
||||
* @param array|string|null $opts
|
||||
* @return Collection
|
||||
*/
|
||||
public static function emptyCollection($opts = null)
|
||||
{
|
||||
return Collection::constructFrom(['data' => []], $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the page object contains no element.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the next page in the resource list (if there is one).
|
||||
*
|
||||
* This method will try to respect the limit of the current page. If none
|
||||
* was given, the default limit will be fetched again.
|
||||
*
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
* @return Collection
|
||||
*/
|
||||
public function nextPage($params = null, $opts = null)
|
||||
{
|
||||
if (!$this->has_more) {
|
||||
return static::emptyCollection($opts);
|
||||
}
|
||||
|
||||
$lastId = end($this->data)->id;
|
||||
|
||||
$params = array_merge(
|
||||
$this->filters,
|
||||
['starting_after' => $lastId],
|
||||
$params ?: []
|
||||
);
|
||||
|
||||
return $this->all($params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the previous page in the resource list (if there is one).
|
||||
*
|
||||
* This method will try to respect the limit of the current page. If none
|
||||
* was given, the default limit will be fetched again.
|
||||
*
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
* @return Collection
|
||||
*/
|
||||
public function previousPage($params = null, $opts = null)
|
||||
{
|
||||
$firstId = $this->data[0]->id;
|
||||
|
||||
$params = array_merge(
|
||||
$this->filters,
|
||||
['ending_before' => $firstId],
|
||||
$params ?: []
|
||||
);
|
||||
|
||||
return $this->all($params, $opts);
|
||||
}
|
||||
|
||||
private function extractPathAndUpdateParams($params)
|
||||
{
|
||||
$url = parse_url($this->url);
|
||||
if (!isset($url['path'])) {
|
||||
throw new Exception\UnexpectedValueException("Could not parse list url into parts: $url");
|
||||
}
|
||||
|
||||
if (isset($url['query'])) {
|
||||
// If the URL contains a query param, parse it out into $params so they
|
||||
// don't interact weirdly with each other.
|
||||
$query = [];
|
||||
parse_str($url['query'], $query);
|
||||
$params = array_merge($params ?: [], $query);
|
||||
}
|
||||
|
||||
return [$url['path'], $params];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class CountrySpec
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property string $default_currency
|
||||
* @property mixed $supported_bank_account_currencies
|
||||
* @property string[] $supported_payment_currencies
|
||||
* @property string[] $supported_payment_methods
|
||||
* @property string[] $supported_transfer_countries
|
||||
* @property mixed $verification_fields
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class CountrySpec extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "country_spec";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Retrieve;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $amount_off
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property string $duration
|
||||
* @property int $duration_in_months
|
||||
* @property bool $livemode
|
||||
* @property int $max_redemptions
|
||||
* @property StripeObject $metadata
|
||||
* @property string $name
|
||||
* @property float $percent_off
|
||||
* @property int $redeem_by
|
||||
* @property int $times_redeemed
|
||||
* @property bool $valid
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Coupon extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "coupon";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Create;
|
||||
use ApiOperations\Delete;
|
||||
use ApiOperations\Retrieve;
|
||||
use ApiOperations\Update;
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class CreditNote
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $amount
|
||||
* @property string $customer_balance_transaction
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property string $customer
|
||||
* @property string $invoice
|
||||
* @property bool $livemode
|
||||
* @property string $memo
|
||||
* @property StripeObject $metadata
|
||||
* @property string $number
|
||||
* @property string $pdf
|
||||
* @property string $reason
|
||||
* @property string $refund
|
||||
* @property string $status
|
||||
* @property string $type
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class CreditNote extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "credit_note";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Create;
|
||||
use ApiOperations\Retrieve;
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of the credit note reason.
|
||||
* @link https://stripe.com/docs/api/credit_notes/object#credit_note_object-reason
|
||||
*/
|
||||
const REASON_DUPLICATE = 'duplicate';
|
||||
const REASON_FRAUDULENT = 'fraudulent';
|
||||
const REASON_ORDER_CHANGE = 'order_change';
|
||||
const REASON_PRODUCT_UNSATISFACTORY = 'product_unsatisfactory';
|
||||
|
||||
/**
|
||||
* Possible string representations of the credit note status.
|
||||
* @link https://stripe.com/docs/api/credit_notes/object#credit_note_object-status
|
||||
*/
|
||||
const STATUS_ISSUED = 'issued';
|
||||
const STATUS_VOID = 'void';
|
||||
|
||||
/**
|
||||
* Possible string representations of the credit note type.
|
||||
* @link https://stripe.com/docs/api/credit_notes/object#credit_note_object-status
|
||||
*/
|
||||
const TYPE_POST_PAYMENT = 'post_payment';
|
||||
const TYPE_PRE_PAYMENT = 'pre_payment';
|
||||
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return CreditNote The voided credit note.
|
||||
*/
|
||||
public function voidCreditNote($params = null, $opts = null)
|
||||
{
|
||||
$url = $this->instanceUrl() . '/void';
|
||||
list($response, $opts) = $this->_request('post', $url, $params, $opts);
|
||||
$this->refreshFrom($response, $opts);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,264 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Customer
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property mixed $address
|
||||
* @property int $balance
|
||||
* @property string $created
|
||||
* @property string $currency
|
||||
* @property string $default_source
|
||||
* @property bool $delinquent
|
||||
* @property string $description
|
||||
* @property Discount $discount
|
||||
* @property string $email
|
||||
* @property string $invoice_prefix
|
||||
* @property mixed $invoice_settings
|
||||
* @property bool $livemode
|
||||
* @property StripeObject $metadata
|
||||
* @property string $name
|
||||
* @property string $phone
|
||||
* @property string[] preferred_locales
|
||||
* @property mixed $shipping
|
||||
* @property Collection $sources
|
||||
* @property Collection $subscriptions
|
||||
* @property string $tax_exempt
|
||||
* @property Collection $tax_ids
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Customer extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "customer";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Create;
|
||||
use ApiOperations\Delete;
|
||||
use ApiOperations\NestedResource;
|
||||
use ApiOperations\Retrieve;
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of the customer's type of tax exemption.
|
||||
* @link https://stripe.com/docs/api/customers/object#customer_object-tax_exempt
|
||||
*/
|
||||
const TAX_EXEMPT_NONE = 'none';
|
||||
const TAX_EXEMPT_EXEMPT = 'exempt';
|
||||
const TAX_EXEMPT_REVERSE = 'reverse';
|
||||
|
||||
public static function getSavedNestedResources()
|
||||
{
|
||||
static $savedNestedResources = null;
|
||||
if ($savedNestedResources === null) {
|
||||
$savedNestedResources = new Util\Set([
|
||||
'source',
|
||||
]);
|
||||
}
|
||||
return $savedNestedResources;
|
||||
}
|
||||
|
||||
const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';
|
||||
const PATH_SOURCES = '/sources';
|
||||
const PATH_TAX_IDS = '/tax_ids';
|
||||
|
||||
/**
|
||||
* @return Customer The updated customer.
|
||||
*/
|
||||
public function deleteDiscount()
|
||||
{
|
||||
$url = $this->instanceUrl() . '/discount';
|
||||
list($response, $opts) = $this->_request('delete', $url);
|
||||
$this->refreshFrom(['discount' => null], $opts, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer on which to create the source.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function createSource($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_createNestedResource($id, static::PATH_SOURCES, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer to which the source belongs.
|
||||
* @param string|null $sourceId The ID of the source to retrieve.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_retrieveNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer to which the source belongs.
|
||||
* @param string|null $sourceId The ID of the source to update.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function updateSource($id, $sourceId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_updateNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer to which the source belongs.
|
||||
* @param string|null $sourceId The ID of the source to delete.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function deleteSource($id, $sourceId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_deleteNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer on which to retrieve the sources.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of sources.
|
||||
*/
|
||||
public static function allSources($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_allNestedResources($id, static::PATH_SOURCES, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer on which to create the tax id.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function createTaxId($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_createNestedResource($id, static::PATH_TAX_IDS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer to which the tax id belongs.
|
||||
* @param string|null $taxIdId The ID of the tax id to retrieve.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function retrieveTaxId($id, $taxIdId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_retrieveNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer to which the tax id belongs.
|
||||
* @param string|null $taxIdId The ID of the tax id to delete.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function deleteTaxId($id, $taxIdId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_deleteNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer on which to retrieve the tax ids.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of tax ids.
|
||||
*/
|
||||
public static function allTaxIds($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer on which to create the balance transaction.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function createBalanceTransaction($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_createNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer to which the balance transaction belongs.
|
||||
* @param string|null $balanceTransactionId The ID of the balance transaction to retrieve.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function retrieveBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_retrieveNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer on which to update the balance transaction.
|
||||
* @param string|null $balanceTransactionId The ID of the balance transaction to update.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return ApiResource
|
||||
*/
|
||||
public static function updateBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
|
||||
{
|
||||
return self::_updateNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $id The ID of the customer on which to retrieve the customer balance transactions.
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Collection The list of customer balance transactions.
|
||||
*/
|
||||
public static function allBalanceTransactions($id, $params = null, $opts = null)
|
||||
{
|
||||
return self::_allNestedResources($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class CustomerBalanceTransaction
|
||||
*
|
||||
* @package Stripe
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $amount
|
||||
* @property string $credit_note
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property string $customer
|
||||
* @property string $description
|
||||
* @property int $ending_balance
|
||||
* @property string $invoice
|
||||
* @property bool $livemode
|
||||
* @property StripeObject $metadata
|
||||
* @property string $type
|
||||
*/
|
||||
class CustomerBalanceTransaction extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "customer_balance_transaction";
|
||||
|
||||
/**
|
||||
* Possible string representations of a balance transaction's type.
|
||||
* @link https://stripe.com/docs/api/customers/customer_balance_transaction_object#customer_balance_transaction_object-type
|
||||
*/
|
||||
const TYPE_ADJUSTEMENT = 'adjustment';
|
||||
const TYPE_APPLIED_TO_INVOICE = 'applied_to_invoice';
|
||||
const TYPE_CREDIT_NOTE = 'credit_note';
|
||||
const TYPE_INITIAL = 'initial';
|
||||
const TYPE_INVOICE_TOO_LARGE = 'invoice_too_large';
|
||||
const TYPE_INVOICE_TOO_SMALL = 'invoice_too_small';
|
||||
const TYPE_UNSPENT_RECEIVER_CREDIT = 'unspent_receiver_credit';
|
||||
|
||||
/**
|
||||
* @return string The API URL for this balance transaction.
|
||||
*/
|
||||
public function instanceUrl()
|
||||
{
|
||||
$id = $this['id'];
|
||||
$customer = $this['customer'];
|
||||
if (!$id) {
|
||||
throw new Exception\UnexpectedValueException(
|
||||
"Could not determine which URL to request: class instance has invalid ID: $id",
|
||||
null
|
||||
);
|
||||
}
|
||||
$id = Util\Util::utf8($id);
|
||||
$customer = Util\Util::utf8($customer);
|
||||
|
||||
$base = Customer::classUrl();
|
||||
$customerExtn = urlencode($customer);
|
||||
$extn = urlencode($id);
|
||||
return "$base/$customerExtn/balance_transactions/$extn";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $_id
|
||||
* @param array|string|null $_opts
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function retrieve($_id, $_opts = null)
|
||||
{
|
||||
$msg = "Customer Balance Transactions cannot be retrieved without a " .
|
||||
"customer ID. Retrieve a Customer Balance Transaction using " .
|
||||
"`Customer::retrieveBalanceTransaction('customer_id', " .
|
||||
"'balance_transaction_id')`.";
|
||||
throw new Exception\BadMethodCallException($msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $_id
|
||||
* @param array|null $_params
|
||||
* @param array|string|null $_options
|
||||
*
|
||||
* @throws \Stripe\Exception\BadMethodCallException
|
||||
*/
|
||||
public static function update($_id, $_params = null, $_options = null)
|
||||
{
|
||||
$msg = "Customer Balance Transactions cannot be updated without a " .
|
||||
"customer ID. Update a Customer Balance Transaction using " .
|
||||
"`Customer::updateBalanceTransaction('customer_id', " .
|
||||
"'balance_transaction_id', \$updateParams)`.";
|
||||
throw new Exception\BadMethodCallException($msg, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Discount
|
||||
*
|
||||
* @property string $object
|
||||
* @property Coupon $coupon
|
||||
* @property string $customer
|
||||
* @property int $end
|
||||
* @property int $start
|
||||
* @property string $subscription
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Discount extends StripeObject
|
||||
{
|
||||
const OBJECT_NAME = "discount";
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Dispute
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $amount
|
||||
* @property BalanceTransaction[] $balance_transactions
|
||||
* @property string $charge
|
||||
* @property int $created
|
||||
* @property string $currency
|
||||
* @property mixed $evidence
|
||||
* @property mixed $evidence_details
|
||||
* @property bool $is_charge_refundable
|
||||
* @property bool $livemode
|
||||
* @property StripeObject $metadata
|
||||
* @property string $reason
|
||||
* @property string $status
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Dispute extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "dispute";
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Retrieve;
|
||||
use ApiOperations\Update;
|
||||
|
||||
/**
|
||||
* Possible string representations of dispute reasons.
|
||||
* @link https://stripe.com/docs/api#dispute_object
|
||||
*/
|
||||
const REASON_BANK_CANNOT_PROCESS = 'bank_cannot_process';
|
||||
const REASON_CHECK_RETURNED = 'check_returned';
|
||||
const REASON_CREDIT_NOT_PROCESSED = 'credit_not_processed';
|
||||
const REASON_CUSTOMER_INITIATED = 'customer_initiated';
|
||||
const REASON_DEBIT_NOT_AUTHORIZED = 'debit_not_authorized';
|
||||
const REASON_DUPLICATE = 'duplicate';
|
||||
const REASON_FRAUDULENT = 'fraudulent';
|
||||
const REASON_GENERAL = 'general';
|
||||
const REASON_INCORRECT_ACCOUNT_DETAILS = 'incorrect_account_details';
|
||||
const REASON_INSUFFICIENT_FUNDS = 'insufficient_funds';
|
||||
const REASON_PRODUCT_NOT_RECEIVED = 'product_not_received';
|
||||
const REASON_PRODUCT_UNACCEPTABLE = 'product_unacceptable';
|
||||
const REASON_SUBSCRIPTION_CANCELED = 'subscription_canceled';
|
||||
const REASON_UNRECOGNIZED = 'unrecognized';
|
||||
|
||||
/**
|
||||
* Possible string representations of dispute statuses.
|
||||
* @link https://stripe.com/docs/api#dispute_object
|
||||
*/
|
||||
const STATUS_CHARGE_REFUNDED = 'charge_refunded';
|
||||
const STATUS_LOST = 'lost';
|
||||
const STATUS_NEEDS_RESPONSE = 'needs_response';
|
||||
const STATUS_UNDER_REVIEW = 'under_review';
|
||||
const STATUS_WARNING_CLOSED = 'warning_closed';
|
||||
const STATUS_WARNING_NEEDS_RESPONSE = 'warning_needs_response';
|
||||
const STATUS_WARNING_UNDER_REVIEW = 'warning_under_review';
|
||||
const STATUS_WON = 'won';
|
||||
|
||||
/**
|
||||
* @param array|string|null $options
|
||||
*
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return Dispute The closed dispute.
|
||||
*/
|
||||
public function close($options = null)
|
||||
{
|
||||
$url = $this->instanceUrl() . '/close';
|
||||
list($response, $opts) = $this->_request('post', $url, null, $options);
|
||||
$this->refreshFrom($response, $opts);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class EphemeralKey
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property int $created
|
||||
* @property int $expires
|
||||
* @property bool $livemode
|
||||
* @property string $secret
|
||||
* @property array $associated_objects
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class EphemeralKey extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "ephemeral_key";
|
||||
|
||||
use ApiOperations\Create {
|
||||
create as protected _create;
|
||||
}
|
||||
use ApiOperations\Delete;
|
||||
|
||||
/**
|
||||
* @param array|null $params
|
||||
* @param array|string|null $opts
|
||||
*
|
||||
* @throws \Stripe\Exception\InvalidArgumentException if stripe_version is missing
|
||||
* @throws \Stripe\Exception\ApiErrorException if the request fails
|
||||
*
|
||||
* @return EphemeralKey The created key.
|
||||
*/
|
||||
public static function create($params = null, $opts = null)
|
||||
{
|
||||
if (!$opts || !isset($opts['stripe_version'])) {
|
||||
throw new Exception\InvalidArgumentException('stripe_version must be specified to create an ephemeral key');
|
||||
}
|
||||
return self::_create($params, $opts);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class ErrorObject
|
||||
*
|
||||
* @property string $charge For card errors, the ID of the failed charge.
|
||||
* @property string $code For some errors that could be handled
|
||||
* programmatically, a short string indicating the error code reported.
|
||||
* @property string $decline_code For card errors resulting from a card issuer
|
||||
* decline, a short string indicating the card issuer's reason for the
|
||||
* decline if they provide one.
|
||||
* @property string $doc_url A URL to more information about the error code
|
||||
* reported.
|
||||
* @property string $message A human-readable message providing more details
|
||||
* about the error. For card errors, these messages can be shown to your
|
||||
* users.
|
||||
* @property string $param If the error is parameter-specific, the parameter
|
||||
* related to the error. For example, you can use this to display a message
|
||||
* near the correct form field.
|
||||
* @property PaymentIntent $payment_intent The PaymentIntent object for errors
|
||||
* returned on a request involving a PaymentIntent.
|
||||
* @property PaymentMethod $payment_method The PaymentMethod object for errors
|
||||
* returned on a request involving a PaymentMethod.
|
||||
* @property SetupIntent $setup_intent The SetupIntent object for errors
|
||||
* returned on a request involving a SetupIntent.
|
||||
* @property StripeObject $source The source object for errors returned on a
|
||||
* request involving a source.
|
||||
* @property string $type The type of error returned. One of
|
||||
* `api_connection_error`, `api_error`, `authentication_error`,
|
||||
* `card_error`, `idempotency_error`, `invalid_request_error`, or
|
||||
* `rate_limit_error`.
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class ErrorObject extends StripeObject
|
||||
{
|
||||
/**
|
||||
* Possible string representations of an error's code.
|
||||
* @link https://stripe.com/docs/error-codes
|
||||
*/
|
||||
const CODE_ACCOUNT_ALREADY_EXISTS = 'account_already_exists';
|
||||
const CODE_ACCOUNT_COUNTRY_INVALID_ADDRESS = 'account_country_invalid_address';
|
||||
const CODE_ACCOUNT_INVALID = 'account_invalid';
|
||||
const CODE_ACCOUNT_NUMBER_INVALID = 'account_number_invalid';
|
||||
const CODE_ALIPAY_UPGRADE_REQUIRED = 'alipay_upgrade_required';
|
||||
const CODE_AMOUNT_TOO_LARGE = 'amount_too_large';
|
||||
const CODE_AMOUNT_TOO_SMALL = 'amount_too_small';
|
||||
const CODE_API_KEY_EXPIRED = 'api_key_expired';
|
||||
const CODE_BALANCE_INSUFFICIENT = 'balance_insufficient';
|
||||
const CODE_BANK_ACCOUNT_EXISTS = 'bank_account_exists';
|
||||
const CODE_BANK_ACCOUNT_UNUSABLE = 'bank_account_unusable';
|
||||
const CODE_BANK_ACCOUNT_UNVERIFIED = 'bank_account_unverified';
|
||||
const CODE_BITCOIN_UPGRADE_REQUIRED = 'bitcoin_upgrade_required';
|
||||
const CODE_CARD_DECLINED = 'card_declined';
|
||||
const CODE_CHARGE_ALREADY_CAPTURED = 'charge_already_captured';
|
||||
const CODE_CHARGE_ALREADY_REFUNDED = 'charge_already_refunded';
|
||||
const CODE_CHARGE_DISPUTED = 'charge_disputed';
|
||||
const CODE_CHARGE_EXCEEDS_SOURCE_LIMIT = 'charge_exceeds_source_limit';
|
||||
const CODE_CHARGE_EXPIRED_FOR_CAPTURE = 'charge_expired_for_capture';
|
||||
const CODE_COUNTRY_UNSUPPORTED = 'country_unsupported';
|
||||
const CODE_COUPON_EXPIRED = 'coupon_expired';
|
||||
const CODE_CUSTOMER_MAX_SUBSCRIPTIONS = 'customer_max_subscriptions';
|
||||
const CODE_EMAIL_INVALID = 'email_invalid';
|
||||
const CODE_EXPIRED_CARD = 'expired_card';
|
||||
const CODE_IDEMPOTENCY_KEY_IN_USE = 'idempotency_key_in_use';
|
||||
const CODE_INCORRECT_ADDRESS = 'incorrect_address';
|
||||
const CODE_INCORRECT_CVC = 'incorrect_cvc';
|
||||
const CODE_INCORRECT_NUMBER = 'incorrect_number';
|
||||
const CODE_INCORRECT_ZIP = 'incorrect_zip';
|
||||
const CODE_INSTANT_PAYOUTS_UNSUPPORTED = 'instant_payouts_unsupported';
|
||||
const CODE_INVALID_CARD_TYPE = 'invalid_card_type';
|
||||
const CODE_INVALID_CHARGE_AMOUNT = 'invalid_charge_amount';
|
||||
const CODE_INVALID_CVC = 'invalid_cvc';
|
||||
const CODE_INVALID_EXPIRY_MONTH = 'invalid_expiry_month';
|
||||
const CODE_INVALID_EXPIRY_YEAR = 'invalid_expiry_year';
|
||||
const CODE_INVALID_NUMBER = 'invalid_number';
|
||||
const CODE_INVALID_SOURCE_USAGE = 'invalid_source_usage';
|
||||
const CODE_INVOICE_NO_CUSTOMER_LINE_ITEMS = 'invoice_no_customer_line_items';
|
||||
const CODE_INVOICE_NO_SUBSCRIPTION_LINE_ITEMS = 'invoice_no_subscription_line_items';
|
||||
const CODE_INVOICE_NOT_EDITABLE = 'invoice_not_editable';
|
||||
const CODE_INVOICE_PAYMENT_INTENT_REQUIRES_ACTION = 'invoice_payment_intent_requires_action';
|
||||
const CODE_INVOICE_UPCOMING_NONE = 'invoice_upcoming_none';
|
||||
const CODE_LIVEMODE_MISMATCH = 'livemode_mismatch';
|
||||
const CODE_LOCK_TIMEOUT = 'lock_timeout';
|
||||
const CODE_MISSING = 'missing';
|
||||
const CODE_NOT_ALLOWED_ON_STANDARD_ACCOUNT = 'not_allowed_on_standard_account';
|
||||
const CODE_ORDER_CREATION_FAILED = 'order_creation_failed';
|
||||
const CODE_ORDER_REQUIRED_SETTINGS = 'order_required_settings';
|
||||
const CODE_ORDER_STATUS_INVALID = 'order_status_invalid';
|
||||
const CODE_ORDER_UPSTREAM_TIMEOUT = 'order_upstream_timeout';
|
||||
const CODE_OUT_OF_INVENTORY = 'out_of_inventory';
|
||||
const CODE_PARAMETER_INVALID_EMPTY = 'parameter_invalid_empty';
|
||||
const CODE_PARAMETER_INVALID_INTEGER = 'parameter_invalid_integer';
|
||||
const CODE_PARAMETER_INVALID_STRING_BLANK = 'parameter_invalid_string_blank';
|
||||
const CODE_PARAMETER_INVALID_STRING_EMPTY = 'parameter_invalid_string_empty';
|
||||
const CODE_PARAMETER_MISSING = 'parameter_missing';
|
||||
const CODE_PARAMETER_UNKNOWN = 'parameter_unknown';
|
||||
const CODE_PARAMETERS_EXCLUSIVE = 'parameters_exclusive';
|
||||
const CODE_PAYMENT_INTENT_AUTHENTICATION_FAILURE = 'payment_intent_authentication_failure';
|
||||
const CODE_PAYMENT_INTENT_INCOMPATIBLE_PAYMENT_METHOD = 'payment_intent_incompatible_payment_method';
|
||||
const CODE_PAYMENT_INTENT_INVALID_PARAMETER = 'payment_intent_invalid_parameter';
|
||||
const CODE_PAYMENT_INTENT_PAYMENT_ATTEMPT_FAILED = 'payment_intent_payment_attempt_failed';
|
||||
const CODE_PAYMENT_INTENT_UNEXPECTED_STATE = 'payment_intent_unexpected_state';
|
||||
const CODE_PAYMENT_METHOD_UNACTIVATED = 'payment_method_unactivated';
|
||||
const CODE_PAYMENT_METHOD_UNEXPECTED_STATE = 'payment_method_unexpected_state';
|
||||
const CODE_PAYOUTS_NOT_ALLOWED = 'payouts_not_allowed';
|
||||
const CODE_PLATFORM_API_KEY_EXPIRED = 'platform_api_key_expired';
|
||||
const CODE_POSTAL_CODE_INVALID = 'postal_code_invalid';
|
||||
const CODE_PROCESSING_ERROR = 'processing_error';
|
||||
const CODE_PRODUCT_INACTIVE = 'product_inactive';
|
||||
const CODE_RATE_LIMIT = 'rate_limit';
|
||||
const CODE_RESOURCE_ALREADY_EXISTS = 'resource_already_exists';
|
||||
const CODE_RESOURCE_MISSING = 'resource_missing';
|
||||
const CODE_ROUTING_NUMBER_INVALID = 'routing_number_invalid';
|
||||
const CODE_SECRET_KEY_REQUIRED = 'secret_key_required';
|
||||
const CODE_SEPA_UNSUPPORTED_ACCOUNT = 'sepa_unsupported_account';
|
||||
const CODE_SETUP_ATTEMPT_FAILED = 'setup_attempt_failed';
|
||||
const CODE_SETUP_INTENT_AUTHENTICATION_FAILURE = 'setup_intent_authentication_failure';
|
||||
const CODE_SETUP_INTENT_UNEXPECTED_STATE = 'setup_intent_unexpected_state';
|
||||
const CODE_SHIPPING_CALCULATION_FAILED = 'shipping_calculation_failed';
|
||||
const CODE_SKU_INACTIVE = 'sku_inactive';
|
||||
const CODE_STATE_UNSUPPORTED = 'state_unsupported';
|
||||
const CODE_TAX_ID_INVALID = 'tax_id_invalid';
|
||||
const CODE_TAXES_CALCULATION_FAILED = 'taxes_calculation_failed';
|
||||
const CODE_TESTMODE_CHARGES_ONLY = 'testmode_charges_only';
|
||||
const CODE_TLS_VERSION_UNSUPPORTED = 'tls_version_unsupported';
|
||||
const CODE_TOKEN_ALREADY_USED = 'token_already_used';
|
||||
const CODE_TOKEN_IN_USE = 'token_in_use';
|
||||
const CODE_TRANSFERS_NOT_ALLOWED = 'transfers_not_allowed';
|
||||
const CODE_UPSTREAM_ORDER_CREATION_FAILED = 'upstream_order_creation_failed';
|
||||
const CODE_URL_INVALID = 'url_invalid';
|
||||
|
||||
/**
|
||||
* Refreshes this object using the provided values.
|
||||
*
|
||||
* @param array $values
|
||||
* @param null|string|array|Util\RequestOptions $opts
|
||||
* @param boolean $partial Defaults to false.
|
||||
*/
|
||||
public function refreshFrom($values, $opts, $partial = false)
|
||||
{
|
||||
// Unlike most other API resources, the API will omit attributes in
|
||||
// error objects when they have a null value. We manually set default
|
||||
// values here to facilitate generic error handling.
|
||||
$values = array_merge([
|
||||
'charge' => null,
|
||||
'code' => null,
|
||||
'decline_code' => null,
|
||||
'doc_url' => null,
|
||||
'message' => null,
|
||||
'param' => null,
|
||||
'payment_intent' => null,
|
||||
'payment_method' => null,
|
||||
'setup_intent' => null,
|
||||
'source' => null,
|
||||
'type' => null,
|
||||
], $values);
|
||||
parent::refreshFrom($values, $opts, $partial);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe;
|
||||
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $object
|
||||
* @property string $account
|
||||
* @property string $api_version
|
||||
* @property int $created
|
||||
* @property mixed $data
|
||||
* @property bool $livemode
|
||||
* @property int $pending_webhooks
|
||||
* @property mixed $request
|
||||
* @property string $type
|
||||
*
|
||||
* @package Stripe
|
||||
*/
|
||||
class Event extends ApiResource
|
||||
{
|
||||
const OBJECT_NAME = "event";
|
||||
|
||||
/**
|
||||
* Possible string representations of event types.
|
||||
* @link https://stripe.com/docs/api#event_types
|
||||
*/
|
||||
const ACCOUNT_UPDATED = 'account.updated';
|
||||
const ACCOUNT_APPLICATION_AUTHORIZED = 'account.application.authorized';
|
||||
const ACCOUNT_APPLICATION_DEAUTHORIZED = 'account.application.deauthorized';
|
||||
const ACCOUNT_EXTERNAL_ACCOUNT_CREATED = 'account.external_account.created';
|
||||
const ACCOUNT_EXTERNAL_ACCOUNT_DELETED = 'account.external_account.deleted';
|
||||
const ACCOUNT_EXTERNAL_ACCOUNT_UPDATED = 'account.external_account.updated';
|
||||
const APPLICATION_FEE_CREATED = 'application_fee.created';
|
||||
const APPLICATION_FEE_REFUNDED = 'application_fee.refunded';
|
||||
const APPLICATION_FEE_REFUND_UPDATED = 'application_fee.refund.updated';
|
||||
const BALANCE_AVAILABLE = 'balance.available';
|
||||
const CHARGE_CAPTURED = 'charge.captured';
|
||||
const CHARGE_EXPIRED = 'charge.expired';
|
||||
const CHARGE_FAILED = 'charge.failed';
|
||||
const CHARGE_PENDING = 'charge.pending';
|
||||
const CHARGE_REFUNDED = 'charge.refunded';
|
||||
const CHARGE_SUCCEEDED = 'charge.succeeded';
|
||||
const CHARGE_UPDATED = 'charge.updated';
|
||||
const CHARGE_DISPUTE_CLOSED = 'charge.dispute.closed';
|
||||
const CHARGE_DISPUTE_CREATED = 'charge.dispute.created';
|
||||
const CHARGE_DISPUTE_FUNDS_REINSTATED = 'charge.dispute.funds_reinstated';
|
||||
const CHARGE_DISPUTE_FUNDS_WITHDRAWN = 'charge.dispute.funds_withdrawn';
|
||||
const CHARGE_DISPUTE_UPDATED = 'charge.dispute.updated';
|
||||
const CHARGE_REFUND_UPDATED = 'charge.refund.updated';
|
||||
const CHECKOUT_SESSION_COMPLETED = 'checkout.session.completed';
|
||||
const COUPON_CREATED = 'coupon.created';
|
||||
const COUPON_DELETED = 'coupon.deleted';
|
||||
const COUPON_UPDATED = 'coupon.updated';
|
||||
const CREDIT_NOTE_CREATED = 'credit_note.created';
|
||||
const CREDIT_NOTE_UPDATED = 'credit_note.updated';
|
||||
const CREDIT_NOTE_VOIDED = 'credit_note.voided';
|
||||
const CUSTOMER_CREATED = 'customer.created';
|
||||
const CUSTOMER_DELETED = 'customer.deleted';
|
||||
const CUSTOMER_UPDATED = 'customer.updated';
|
||||
const CUSTOMER_DISCOUNT_CREATED = 'customer.discount.created';
|
||||
const CUSTOMER_DISCOUNT_DELETED = 'customer.discount.deleted';
|
||||
const CUSTOMER_DISCOUNT_UPDATED = 'customer.discount.updated';
|
||||
const CUSTOMER_SOURCE_CREATED = 'customer.source.created';
|
||||
const CUSTOMER_SOURCE_DELETED = 'customer.source.deleted';
|
||||
const CUSTOMER_SOURCE_EXPIRING = 'customer.source.expiring';
|
||||
const CUSTOMER_SOURCE_UPDATED = 'customer.source.updated';
|
||||
const CUSTOMER_SUBSCRIPTION_CREATED = 'customer.subscription.created';
|
||||
const CUSTOMER_SUBSCRIPTION_DELETED = 'customer.subscription.deleted';
|
||||
const CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END = 'customer.subscription.trial_will_end';
|
||||
const CUSTOMER_SUBSCRIPTION_UPDATED = 'customer.subscription.updated';
|
||||
const FILE_CREATED = 'file.created';
|
||||
const INVOICE_CREATED = 'invoice.created';
|
||||
const INVOICE_DELETED = 'invoice.deleted';
|
||||
const INVOICE_FINALIZED = 'invoice.finalized';
|
||||
const INVOICE_MARKED_UNCOLLECTIBLE = 'invoice.marked_uncollectible';
|
||||
const INVOICE_PAYMENT_ACTION_REQUIRED = 'invoice.payment_action_required';
|
||||
const INVOICE_PAYMENT_FAILED = 'invoice.payment_failed';
|
||||
const INVOICE_PAYMENT_SUCCEEDED = 'invoice.payment_succeeded';
|
||||
const INVOICE_SENT = 'invoice.sent';
|
||||
const INVOICE_UPCOMING = 'invoice.upcoming';
|
||||
const INVOICE_UPDATED = 'invoice.updated';
|
||||
const INVOICE_VOIDED = 'invoice.voided';
|
||||
const INVOICEITEM_CREATED = 'invoiceitem.created';
|
||||
const INVOICEITEM_DELETED = 'invoiceitem.deleted';
|
||||
const INVOICEITEM_UPDATED = 'invoiceitem.updated';
|
||||
const ISSUER_FRAUD_RECORD_CREATED = 'issuer_fraud_record.created';
|
||||
const ISSUING_AUTHORIZATION_CREATED = 'issuing_authorization.created';
|
||||
const ISSUING_AUTHORIZATION_REQUEST = 'issuing_authorization.request';
|
||||
const ISSUING_AUTHORIZATION_UPDATED = 'issuing_authorization.updated';
|
||||
const ISSUING_CARD_CREATED = 'issuing_card.created';
|
||||
const ISSUING_CARD_UPDATED = 'issuing_card.updated';
|
||||
const ISSUING_CARDHOLDER_CREATED = 'issuing_cardholder.created';
|
||||
const ISSUING_CARDHOLDER_UPDATED = 'issuing_cardholder.updated';
|
||||
const ISSUING_DISPUTE_CREATED = 'issuing_dispute.created';
|
||||
const ISSUING_DISPUTE_UPDATED = 'issuing_dispute.updated';
|
||||
const ISSUING_TRANSACTION_CREATED = 'issuing_transaction.created';
|
||||
const ISSUING_TRANSACTION_UPDATED = 'issuing_transaction.updated';
|
||||
const ORDER_CREATED = 'order.created';
|
||||
const ORDER_PAYMENT_FAILED = 'order.payment_failed';
|
||||
const ORDER_PAYMENT_SUCCEEDED = 'order.payment_succeeded';
|
||||
const ORDER_UPDATED = 'order.updated';
|
||||
const ORDER_RETURN_CREATED = 'order_return.created';
|
||||
const PAYMENT_INTENT_AMOUNT_CAPTURABLE_UPDATED = 'payment_intent.amount_capturable_updated';
|
||||
const PAYMENT_INTENT_CREATED = 'payment_intent.created';
|
||||
const PAYMENT_INTENT_PAYMENT_FAILED = 'payment_intent.payment_failed';
|
||||
const PAYMENT_INTENT_SUCCEEDED = 'payment_intent.succeeded';
|
||||
const PAYMENT_METHOD_ATTACHED = 'payment_method.attached';
|
||||
const PAYMENT_METHOD_CARD_AUTOMATICALLY_UPDATED = 'payment_method.card_automatically_updated';
|
||||
const PAYMENT_METHOD_DETACHED = 'payment_method.detached';
|
||||
const PAYMENT_METHOD_UPDATED = 'payment_method.updated';
|
||||
const PAYOUT_CANCELED = 'payout.canceled';
|
||||
const PAYOUT_CREATED = 'payout.created';
|
||||
const PAYOUT_FAILED = 'payout.failed';
|
||||
const PAYOUT_PAID = 'payout.paid';
|
||||
const PAYOUT_UPDATED = 'payout.updated';
|
||||
const PERSON_CREATED = 'person.created';
|
||||
const PERSON_DELETED = 'person.deleted';
|
||||
const PERSON_UPDATED = 'person.updated';
|
||||
const PING = 'ping';
|
||||
const PLAN_CREATED = 'plan.created';
|
||||
const PLAN_DELETED = 'plan.deleted';
|
||||
const PLAN_UPDATED = 'plan.updated';
|
||||
const PRODUCT_CREATED = 'product.created';
|
||||
const PRODUCT_DELETED = 'product.deleted';
|
||||
const PRODUCT_UPDATED = 'product.updated';
|
||||
const RECIPIENT_CREATED = 'recipient.created';
|
||||
const RECIPIENT_DELETED = 'recipient.deleted';
|
||||
const RECIPIENT_UPDATED = 'recipient.updated';
|
||||
const REPORTING_REPORT_RUN_FAILED = 'reporting.report_run.failed';
|
||||
const REPORTING_REPORT_RUN_SUCCEEDED = 'reporting.report_run.succeeded';
|
||||
const REPORTING_REPORT_TYPE_UPDATED = 'reporting.report_type.updated';
|
||||
const REVIEW_CLOSED = 'review.closed';
|
||||
const REVIEW_OPENED = 'review.opened';
|
||||
const SIGMA_SCHEDULED_QUERY_RUN_CREATED = 'sigma.scheduled_query_run.created';
|
||||
const SKU_CREATED = 'sku.created';
|
||||
const SKU_DELETED = 'sku.deleted';
|
||||
const SKU_UPDATED = 'sku.updated';
|
||||
const SOURCE_CANCELED = 'source.canceled';
|
||||
const SOURCE_CHARGEABLE = 'source.chargeable';
|
||||
const SOURCE_FAILED = 'source.failed';
|
||||
const SOURCE_MANDATE_NOTIFICATION = 'source.mandate_notification';
|
||||
const SOURCE_REFUND_ATTRIBUTES_REQUIRED = 'source.refund_attributes_required';
|
||||
const SOURCE_TRANSACTION_CREATED = 'source.transaction.created';
|
||||
const SOURCE_TRANSACTION_UPDATED = 'source.transaction.updated';
|
||||
const SUBSCRIPTION_SCHEDULE_ABORTED = 'subscription_schedule.aborted';
|
||||
const SUBSCRIPTION_SCHEDULE_CANCELED = 'subscription_schedule.canceled';
|
||||
const SUBSCRIPTION_SCHEDULE_COMPLETED = 'subscription_schedule.completed';
|
||||
const SUBSCRIPTION_SCHEDULE_CREATED = 'subscription_schedule.created';
|
||||
const SUBSCRIPTION_SCHEDULE_EXPIRING = 'subscription_schedule.expiring';
|
||||
const SUBSCRIPTION_SCHEDULE_RELEASED = 'subscription_schedule.released';
|
||||
const SUBSCRIPTION_SCHEDULE_UPDATED = 'subscription_schedule.updated';
|
||||
const TAX_RATE_CREATED = 'tax_rate.created';
|
||||
const TAX_RATE_UPDATED = 'tax_rate.updated';
|
||||
const TOPUP_CANCELED = 'topup.canceled';
|
||||
const TOPUP_CREATED = 'topup.created';
|
||||
const TOPUP_FAILED = 'topup.failed';
|
||||
const TOPUP_REVERSED = 'topup.reversed';
|
||||
const TOPUP_SUCCEEDED = 'topup.succeeded';
|
||||
const TRANSFER_CREATED = 'transfer.created';
|
||||
const TRANSFER_REVERSED = 'transfer.reversed';
|
||||
const TRANSFER_UPDATED = 'transfer.updated';
|
||||
|
||||
use ApiOperations\All;
|
||||
use ApiOperations\Retrieve;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
/**
|
||||
* ApiConnection is thrown in the event that the SDK can't connect to Stripe's
|
||||
* servers. That can be for a variety of different reasons from a downed
|
||||
* network to a bad TLS certificate.
|
||||
*
|
||||
* @package Stripe\Exception
|
||||
*/
|
||||
class ApiConnectionException extends ApiErrorException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
/**
|
||||
* Implements properties and methods common to all (non-SPL) Stripe exceptions.
|
||||
*/
|
||||
abstract class ApiErrorException extends \Exception implements ExceptionInterface
|
||||
{
|
||||
protected $error;
|
||||
protected $httpBody;
|
||||
protected $httpHeaders;
|
||||
protected $httpStatus;
|
||||
protected $jsonBody;
|
||||
protected $requestId;
|
||||
protected $stripeCode;
|
||||
|
||||
/**
|
||||
* Creates a new API error exception.
|
||||
*
|
||||
* @param string $message The exception message.
|
||||
* @param int|null $httpStatus The HTTP status code.
|
||||
* @param string|null $httpBody The HTTP body as a string.
|
||||
* @param array|null $jsonBody The JSON deserialized body.
|
||||
* @param array|\Stripe\Util\CaseInsensitiveArray|null $httpHeaders The HTTP headers array.
|
||||
* @param string|null $stripeCode The Stripe error code.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function factory(
|
||||
$message,
|
||||
$httpStatus = null,
|
||||
$httpBody = null,
|
||||
$jsonBody = null,
|
||||
$httpHeaders = null,
|
||||
$stripeCode = null
|
||||
) {
|
||||
$instance = new static($message);
|
||||
$instance->setHttpStatus($httpStatus);
|
||||
$instance->setHttpBody($httpBody);
|
||||
$instance->setJsonBody($jsonBody);
|
||||
$instance->setHttpHeaders($httpHeaders);
|
||||
$instance->setStripeCode($stripeCode);
|
||||
|
||||
$instance->setRequestId(null);
|
||||
if ($httpHeaders && isset($httpHeaders['Request-Id'])) {
|
||||
$instance->setRequestId($httpHeaders['Request-Id']);
|
||||
}
|
||||
|
||||
$instance->setError($instance->constructErrorObject());
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Stripe error object.
|
||||
*
|
||||
* @return \Stripe\ErrorObject|null
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Stripe error object.
|
||||
*
|
||||
* @param \Stripe\ErrorObject|null $error
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP body as a string.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getHttpBody()
|
||||
{
|
||||
return $this->httpBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP body as a string.
|
||||
*
|
||||
* @param string|null $httpBody
|
||||
*/
|
||||
public function setHttpBody($httpBody)
|
||||
{
|
||||
$this->httpBody = $httpBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP headers array.
|
||||
*
|
||||
* @return array|\Stripe\Util\CaseInsensitiveArray|null
|
||||
*/
|
||||
public function getHttpHeaders()
|
||||
{
|
||||
return $this->httpHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP headers array.
|
||||
*
|
||||
* @param array|\Stripe\Util\CaseInsensitiveArray|null $httpHeaders
|
||||
*/
|
||||
public function setHttpHeaders($httpHeaders)
|
||||
{
|
||||
$this->httpHeaders = $httpHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP status code.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getHttpStatus()
|
||||
{
|
||||
return $this->httpStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP status code.
|
||||
*
|
||||
* @param int|null $httpStatus
|
||||
*/
|
||||
public function setHttpStatus($httpStatus)
|
||||
{
|
||||
$this->httpStatus = $httpStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the JSON deserialized body.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getJsonBody()
|
||||
{
|
||||
return $this->jsonBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the JSON deserialized body.
|
||||
*
|
||||
* @param array|null $jsonBody
|
||||
*/
|
||||
public function setJsonBody($jsonBody)
|
||||
{
|
||||
$this->jsonBody = $jsonBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Stripe request ID.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Stripe request ID.
|
||||
*
|
||||
* @param string|null $requestId
|
||||
*/
|
||||
public function setRequestId($requestId)
|
||||
{
|
||||
$this->requestId = $requestId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Stripe error code.
|
||||
*
|
||||
* Cf. the `CODE_*` constants on {@see \Stripe\ErrorObject} for possible
|
||||
* values.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStripeCode()
|
||||
{
|
||||
return $this->stripeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Stripe error code.
|
||||
*
|
||||
* @param string|null $stripeCode
|
||||
*/
|
||||
public function setStripeCode($stripeCode)
|
||||
{
|
||||
$this->stripeCode = $stripeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of the exception.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$statusStr = ($this->getHttpStatus() == null) ? "" : "(Status {$this->getHttpStatus()}) ";
|
||||
$idStr = ($this->getRequestId() == null) ? "" : "(Request {$this->getRequestId()}) ";
|
||||
return "{$statusStr}{$idStr}{$this->getMessage()}";
|
||||
}
|
||||
|
||||
protected function constructErrorObject()
|
||||
{
|
||||
if (is_null($this->jsonBody) || !array_key_exists('error', $this->jsonBody)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Stripe\ErrorObject::constructFrom($this->jsonBody['error']);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
/**
|
||||
* AuthenticationException is thrown when invalid credentials are used to
|
||||
* connect to Stripe's servers.
|
||||
*
|
||||
* @package Stripe\Exception
|
||||
*/
|
||||
class AuthenticationException extends ApiErrorException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
/**
|
||||
* CardException is thrown when a user enters a card that can't be charged for
|
||||
* some reason.
|
||||
*
|
||||
* @package Stripe\Exception
|
||||
*/
|
||||
class CardException extends ApiErrorException
|
||||
{
|
||||
protected $declineCode;
|
||||
protected $stripeParam;
|
||||
|
||||
/**
|
||||
* Creates a new CardException exception.
|
||||
*
|
||||
* @param string $message The exception message.
|
||||
* @param int|null $httpStatus The HTTP status code.
|
||||
* @param string|null $httpBody The HTTP body as a string.
|
||||
* @param array|null $jsonBody The JSON deserialized body.
|
||||
* @param array|\Stripe\Util\CaseInsensitiveArray|null $httpHeaders The HTTP headers array.
|
||||
* @param string|null $stripeCode The Stripe error code.
|
||||
* @param string|null $declineCode The decline code.
|
||||
* @param string|null $stripeParam The parameter related to the error.
|
||||
*
|
||||
* @return CardException
|
||||
*/
|
||||
public static function factory(
|
||||
$message,
|
||||
$httpStatus = null,
|
||||
$httpBody = null,
|
||||
$jsonBody = null,
|
||||
$httpHeaders = null,
|
||||
$stripeCode = null,
|
||||
$declineCode = null,
|
||||
$stripeParam = null
|
||||
) {
|
||||
$instance = parent::factory($message, $httpStatus, $httpBody, $jsonBody, $httpHeaders, $stripeCode);
|
||||
$instance->setDeclineCode($declineCode);
|
||||
$instance->setStripeParam($stripeParam);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the decline code.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDeclineCode()
|
||||
{
|
||||
return $this->declineCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the decline code.
|
||||
*
|
||||
* @param string|null $declineCode
|
||||
*/
|
||||
public function setDeclineCode($declineCode)
|
||||
{
|
||||
$this->declineCode = $declineCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameter related to the error.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStripeParam()
|
||||
{
|
||||
return $this->stripeParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter related to the error.
|
||||
*
|
||||
* @param string|null $stripeParam
|
||||
*/
|
||||
public function setStripeParam($stripeParam)
|
||||
{
|
||||
$this->stripeParam = $stripeParam;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
// TODO: remove this check once we drop support for PHP 5
|
||||
if (interface_exists(\Throwable::class)) {
|
||||
/**
|
||||
* The base interface for all Stripe exceptions.
|
||||
*
|
||||
* @package Stripe\Exception
|
||||
*/
|
||||
interface ExceptionInterface extends \Throwable
|
||||
{
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* The base interface for all Stripe exceptions.
|
||||
*
|
||||
* @package Stripe\Exception
|
||||
*/
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
|
||||
interface ExceptionInterface
|
||||
{
|
||||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
/**
|
||||
* IdempotencyException is thrown in cases where an idempotency key was used
|
||||
* improperly.
|
||||
*
|
||||
* @package Stripe\Exception
|
||||
*/
|
||||
class IdempotencyException extends ApiErrorException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception;
|
||||
|
||||
/**
|
||||
* InvalidRequestException is thrown when a request is initiated with invalid
|
||||
* parameters.
|
||||
*
|
||||
* @package Stripe\Exception
|
||||
*/
|
||||
class InvalidRequestException extends ApiErrorException
|
||||
{
|
||||
protected $stripeParam;
|
||||
|
||||
/**
|
||||
* Creates a new InvalidRequestException exception.
|
||||
*
|
||||
* @param string $message The exception message.
|
||||
* @param int|null $httpStatus The HTTP status code.
|
||||
* @param string|null $httpBody The HTTP body as a string.
|
||||
* @param array|null $jsonBody The JSON deserialized body.
|
||||
* @param array|\Stripe\Util\CaseInsensitiveArray|null $httpHeaders The HTTP headers array.
|
||||
* @param string|null $stripeCode The Stripe error code.
|
||||
* @param string|null $stripeParam The parameter related to the error.
|
||||
*
|
||||
* @return InvalidRequestException
|
||||
*/
|
||||
public static function factory(
|
||||
$message,
|
||||
$httpStatus = null,
|
||||
$httpBody = null,
|
||||
$jsonBody = null,
|
||||
$httpHeaders = null,
|
||||
$stripeCode = null,
|
||||
$stripeParam = null
|
||||
) {
|
||||
$instance = parent::factory($message, $httpStatus, $httpBody, $jsonBody, $httpHeaders, $stripeCode);
|
||||
$instance->setStripeParam($stripeParam);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameter related to the error.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStripeParam()
|
||||
{
|
||||
return $this->stripeParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter related to the error.
|
||||
*
|
||||
* @param string|null $stripeParam
|
||||
*/
|
||||
public function setStripeParam($stripeParam)
|
||||
{
|
||||
$this->stripeParam = $stripeParam;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception\OAuth;
|
||||
|
||||
/**
|
||||
* The base interface for all Stripe OAuth exceptions.
|
||||
*/
|
||||
interface ExceptionInterface extends \Stripe\Exception\ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception\OAuth;
|
||||
|
||||
/**
|
||||
* InvalidClientException is thrown when the client_id does not belong to you,
|
||||
* the stripe_user_id does not exist or is not connected to your application,
|
||||
* or the API key mode (live or test mode) does not match the client_id mode.
|
||||
*
|
||||
* @package Stripe\Exception\OAuth
|
||||
*/
|
||||
class InvalidClientException extends OAuthErrorException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception\OAuth;
|
||||
|
||||
/**
|
||||
* InvalidGrantException is thrown when a specified code doesn't exist, is
|
||||
* expired, has been used, or doesn't belong to you; a refresh token doesn't
|
||||
* exist, or doesn't belong to you; or if an API key's mode (live or test)
|
||||
* doesn't match the mode of a code or refresh token.
|
||||
*
|
||||
* @package Stripe\Exception\OAuth
|
||||
*/
|
||||
class InvalidGrantException extends OAuthErrorException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception\OAuth;
|
||||
|
||||
/**
|
||||
* InvalidRequestException is thrown when a code, refresh token, or grant
|
||||
* type parameter is not provided, but was required.
|
||||
*
|
||||
* @package Stripe\Exception\OAuth
|
||||
*/
|
||||
class InvalidRequestException extends OAuthErrorException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception\OAuth;
|
||||
|
||||
/**
|
||||
* InvalidScopeException is thrown when an invalid scope parameter is provided.
|
||||
*
|
||||
* @package Stripe\Exception\OAuth
|
||||
*/
|
||||
class InvalidScopeException extends OAuthErrorException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Stripe\Exception\OAuth;
|
||||
|
||||
/**
|
||||
* Implements properties and methods common to all (non-SPL) Stripe OAuth
|
||||
* exceptions.
|
||||
*/
|
||||
abstract class OAuthErrorException extends \Stripe\Exception\ApiErrorException
|
||||
{
|
||||
protected function constructErrorObject()
|
||||
{
|
||||
if (is_null($this->jsonBody)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Stripe\OAuthErrorObject::constructFrom($this->jsonBody);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue