I am creating App for Quickbook in PHP
I am using https://github.com/intuit/QuickBooks-V3-PHP-SDK/
I want to make payments to multiple invoice in single API call.
I see their example but those make single payment. I need multiple payments towards various invoice for different customers.
How that is possible?
Their example code is here:
https://github.com/IntuitDeveloper/SampleApp-CRUD-PHP/blob/master/CRUD_Examples/Payment/PaymentCreate.php
So here's a snippet:
$theResourceObj = Payment::create([
"CustomerRef" =>
[
"value" => "1"
],
"TotalAmt" => 100.00,
"Line" => [
[
"Amount" => 100.00,
"LinkedTxn" => [
[
"TxnId" => "210",
"TxnType" => "Invoice"
]]
]]
]);
$resultingObj = $dataService->Add($theResourceObj);
Then if you refer to their documentation:
https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/payment#the-payment-object
You can see that the Line element is composed of Zero or more transactions accounting for this payment. including The invoice to which payment is applied. i.e. you can repeat things within Line, to apply the payment to more than one invoice.
So applying a payment to more than one invoice lists each individual invoice, and the amount of the payment to apply, in the repeating Line node array:
$theResourceObj = Payment::create([
"CustomerRef" =>
[
"value" => "1"
],
"TotalAmt" => 100.00,
"Line" => [
[
"Amount" => 50.00,
"LinkedTxn" => [
[
"TxnId" => "210",
"TxnType" => "Invoice"
]]
],
[
"Amount" => 25.00,
"LinkedTxn" => [
[
"TxnId" => "211",
"TxnType" => "Invoice"
]]
],
[
"Amount" => 25.00,
"LinkedTxn" => [
[
"TxnId" => "212",
"TxnType" => "Invoice"
]]
],
]
]);
$resultingObj = $dataService->Add($theResourceObj);
Finally I found solution for me.
API have Batch Option to add multiple Objects in single Batch.
Thanks to everyone
Related
In the application, we have a feature to download the wallet card into the Apple wallet as a contact card.
We have created this wallet contact card from the PHP code - below.
$data = [
'description' => 'MyApp',
'formatVersion' => 1,
'organizationName' => 'My app',
'passTypeIdentifier' => 'pass.test.test',
'serialNumber' => '12345678',
'teamIdentifier' => '*********',
'storeCard' => [
"headerFields" => [
[
"key" => "header-text",
"label" => "Let's connect",
"value" => "Together"
]
],
"auxiliaryFields" => [
[
"key" => "aux-text-two",
"label" => "",
"value" => ""
],
[
"key" => "aux-text-one",
"label" => "www.abc.com",
"value" => ""
]
],
"primaryFields" => [],
'secondaryFields' => [],
'backFields' => [],
],
'barcode' => [
'format' => 'PKBarcodeFormatQR',
'message' => 'https://abc.1-2-3-4-5.xyz/public/myapp/?id='.$userData->token.'',
'messageEncoding' => 'iso-8859-1',
],
"backgroundColor" => "rgb(255,255,255)",
'logoText' => '',
'relevantDate' => date('Y-m-d\TH:i:sP'),
"expirationDate" => "2030-01-01T23:00:00Z",
];
We are requesting an apple wallet card to be generated from the iOS code calling API for this - below.
if PKPassLibrary.isPassLibraryAvailable(){
if let data = try? Data(contentsOf: url){
if let pass = try? PKPass(data: data){
let passLibrary = PKPassLibrary()
if !passLibrary.containsPass(pass),
let passController = PKAddPassesViewController(pass: pass){
passController.delegate = self
self.present(passController, animated: true)
}else{
ShowAlert(message: "contact_card_already_exist".localize(), theme: .error)
}
}
}
}
As screenshots say - it’s valid till 1/1/30, PHP code we have given the expiry date as well, but still, the wallet card is gone to Expired in 2 days.
Any help is appreciated.
I used mongodb db.version() 5.0.9 with PHP 7.4.30
I worked with queue based on mongo db and in architecure present possibility to scaling, so could be several workers. My question - how I can protect my record from the concurence query, when two workers try to execute findOneAndUpdate in the same time ? Or maybe findOneAndUpdate has this opportunity by default ?
$document = $this->collection->findOneAndUpdate(
[
'$and' => [
[
'job_type' => 'metrics'
],
$conditionDelivered,
[
'id.pub_key_digest' => [
'$exists' => true
]
],
[
'timestamp' => [
'$gt' => $timestampOffset
]
],
],
],
[
'$set' => $setSection,
],
[
'sort' => [
'timestamp' => 1,
],
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER
]
);
$filter
{"$and":[{"job_type":"metrics"},{"alert_delivered_at":{"$exists":false},"timescale_delivered_at":{"$exists":false}},{"id.pub_key_digest":{"$exists":true}},{"timestamp":{"$gt":1291852800000000000}}]}
$update
{"$set":{"alert_consumer_id":"consumer_62b2d4e4520339.76461865","alert_delivered_at":{"$date":{"$numberLong":"1655887076643"}},"timescale_delivered_at":{"$date":{"$numberLong":"1655887076643"}}}}
and $options
{"sort":{"timestamp":1},"writeConcern":{"w":"majority"},"returnDocument":2}
Could you explain please best way for find and update data with guarantee which will be executed by only one worker, some lock, the other workers will be work with another records ?
I'm trying to generate an invoice through stripe but the API requires a Client ID which I have no idea how to retrieve.
I'm using Session checkout:
method called by ajax
$checkout_session = Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'unit_amount' => 2000,
'product_data' => [
'name' => 'Stubborn Attachments',
'images' => ["https://i.imgur.com/EHyR2nP.png"],
],
],
'quantity' => 1,
]],
'customer_email' => $email,
'mode' => 'payment',
'success_url' => $domain. '/success/{CHECKOUT_SESSION_ID}',
'cancel_url' => $domain. '/cancel/{CHECKOUT_SESSION_ID}',
]);
I receive
[
"id" => "cs_test_xxxxxxxxxxxxxxxx"
"object" => "checkout.session"
"allow_promotion_codes" => null
"amount_subtotal" => 2000
"amount_total" => 2000
"billing_address_collection" => null
"cancel_url" => "http://localhost/cancel/{CHECKOUT_SESSION_ID}"
"client_reference_id" => null
"currency" => "usd"
"customer" => null
"customer_details" => null
"customer_email" => "xxxxxxxxxxx#gmail.com"
"livemode" => false
"locale" => null
"metadata" => []
"mode" => "payment"
"payment_intent" => "pi_xxxxxxxxxxxxx"
"payment_method_options" => []
"payment_method_types" => array:1 [
0 => "card"
]
"payment_status" => "unpaid"
"setup_intent" => null
"shipping" => null
"shipping_address_collection" => null
"submit_type" => null
"subscription" => null
"success_url" => "http://localhost/success/{CHECKOUT_SESSION_ID}"
"total_details" => array:3 [
"amount_discount" => 0
"amount_shipping" => 0
"amount_tax" => 0
]
]
Create invoice requires a customer id which I don't have and have no idea where to get since session checkout creates a customer without giving me an id.
A Checkout Session in payment mode will generate a Payment Intent, not an Invoice. If you want to work solely with Invoices, you Checkout Session is not the right solution. If you don't care about Invoices and just want to be able to charge a customer for a one-off payment then you can continue using Checkout.
If you do want to work solely with Invoices, you need to do the following:
Create a Customer
Pass in the Customer ID when you create as many Invoice Items as you need
Pass in the Customer ID when you create an Invoice - this will automatically pull in any pending Invoice Items tied to the customer.
This is all summarized in this guide: https://stripe.com/docs/invoicing/integration
I'm using Stripe PHP SDK to create a subscription plan dynamically.
use \Stripe\Plan;
Plan::create(array(
"amount" => 2000,
"interval" => "month",
"name" => "Amazing Gold Plan",
"currency" => "usd",
"id" => "gold")
);
I wanted to ask is there a way to mention/handle the duration of a plan. Like I wanted to make a subscription by the plan for a limited time suppose 3 months and after 3 months I wanted the plan to automatically get removed from the subscription. I don't want to cancel the whole subscription as in my case there could be multiple plans associated with a subscription. SO I simply want to remove/detach the plan from the subscription.
I had gone through the Stripe SDK docs to find this but to no avail.
A Subscription Schedule [1] will be what you require here to automate changes to the underlying Subscription using phases [2].
The use of a schedule will allow you to specify, for example, a monthly Price that will iterate for 3 months in the first phase. Then you can define in the next phase what will happen, for example change the Prices in some way, like adding or removing Prices. An example may look like this:
\Stripe\SubscriptionSchedule::create([
'customer' => 'cus_xxx',
'start_date' => 'now',
'end_behavior' => 'release',
'phases' => [
[
'items' => [
[
'price' => 'price_print', # Monthly Price
'quantity' => 1,
],
],
'iterations' => 3, # Iterates for 3 months
],
[
'items' => [
[
'price' => 'price_print',
'quantity' => 1,
],
[
'price' => 'price_digital', # An extra price
'quantity' => 1,
],
],
'iterations' => 1, # Iterate for 1 month
],
],
]);
[1] https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing
[2] https://stripe.com/docs/api/subscription_schedules/object#subscription_schedule_object-phases
I believe you need to create price instead of plan and the code would be like this (Not sure I use different platform but you can try)
use \Stripe\Plan;
$price = \Stripe\Price::create([
'product' => '{{PRODUCT_ID}}',
'unit_amount' => 1000,
'currency' => 'usd',
'recurring' => [
'interval' => 'month',
'interval_count' => 2 //Try tweaking this value for change
],
]);
I'm trying to change a ranges colour via the Google Sheets API in PHP.
I have done around an hour of researchig. The code below is as far as I've got.
$requests = [
// Change the spreadsheet's title.
new Google_Service_Sheets_Request([
'updateSpreadsheetProperties' => [
'properties' => [
'title' => "The Title"
],
'fields' => 'title'
],
'UpdateCellsRequest' => [
'properties' => [
'range' => "Sheet1!A1",
'backgroundColor' => "#000"
],
'fields' => ''
]
])
];
// Add additional requests (operations) ...
$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => $requests
]);
$response = $GoogleSheetsAPIHandler->sheets->spreadsheets->batchUpdate("SHEETID", $batchUpdateRequest);
print_r($response);
If I take out this:
'UpdateCellsRequest' => [
'properties' => [
'range' => "Sheet1!A1",
'backgroundColor' => "#000"
],
'fields' => ''
]
Then the code works to update the sheets title. However, I can't seem to update a ranges colour.
Any advice would be greatly appreciated!
I believe your goal and situation as follows.
You want to change the background color of cells using googleapis for php.
You have already been able to get and put values for Google Spreadsheet using Sheets API.
Modification points:
When you want to use the batchUpdate method of Sheets API, please put each request to each element of the array of requests.
I think that the request body of UpdateCellsRequest in your script is not correct.
From your question of I'm trying to change a ranges colour via the Google Sheets API in PHP., when you want to change the background color of several cells with one color, I think that RepeatCellRequest might be suitable.
In this answer, I would like to propose a modified script for changing the several cells using one color. When your script is modified, it becomes as follows.
Modified script:
Before you use this, please set the sheet ID.
$requests = [
new Google_Service_Sheets_Request([
'updateSpreadsheetProperties' => [
'properties' => [
'title' => "The Title"
],
'fields' => 'title'
]
]),
new Google_Service_Sheets_Request([
'repeatCell' => [
'cell' => [
'userEnteredFormat' => [
'backgroundColor' => [
'red' => 1,
'green' => 0,
'blue' => 0
]
]
],
'range' => [
'sheetId' => $sheetId, // <--- Please set the sheet ID.
'startRowIndex' => 0,
'endRowIndex' => 3,
'startColumnIndex' => 0,
'endColumnIndex' => 2
],
'fields' => 'userEnteredFormat'
]
])
];
When above request body is used for the batchUpdate method of Sheets API, the title of Spreadsheet is changed and the background color of the cells "A1:B3" changed to the red color.
Wne you want to use UpdateCellsRequest, you can use the following request body. At the following request body, the background colors of cells "A1:B1" are changed to red and green colors, respectively. When UpdateCellsRequest is used, each cell can be updated. About the detail information of UpdateCellsRequest, please check the official document. Ref
$requests = [
new Google_Service_Sheets_Request([
'updateCells' => [
'rows' => array([
'values' => array(
['userEnteredFormat' => [
'backgroundColor' => [
'red' => 1,
'green' => 0,
'blue' => 0
]
]],
['userEnteredFormat' => [
'backgroundColor' => [
'red' => 0,
'green' => 1,
'blue' => 0
]
]]
)
]),
'range' => [
'sheetId' => $sheetId, // <--- Please set the sheet ID.
'startRowIndex' => 0,
'startColumnIndex' => 0,
],
'fields' => 'userEnteredFormat'
]
])
];
References:
UpdateCellsRequest
RepeatCellRequest