I'm trying to refund an adaptive payment chained payment totally to the sender, but I'm stuck. I'm using CodeIgniter and Andrew Angell's awesome library for adaptive payments.
The refund I want to make has details like this: (you can see the raw xml requests and responds below)
Array
(
[Errors] => Array
(
)
[Ack] => Success
[Build] => 5472483
[CorrelationID] => 4d31bf900a109
[Timestamp] => 2013-03-20T09:45:02.585-07:00
[ActionType] => PAY_PRIMARY
[CancelURL] => http://my-cancel-url.com
[CurrencyCode] => TRY
[FeesPayer] => PRIMARYRECEIVER
[FundingTypes] => Array
(
)
[IPNNotificationURL] =>
[Memo] =>
[PayKey] => my-paykey
[PaymentInfo] => Array
(
[PendingRefund] => false
[RefundAmount] => 0.00
[SenderTransactionID] =>
[SenderTransactionStatus] => COMPLETED
[TransactionID] => my-transaction-id
[TransactionStatus] => COMPLETED
)
[PreapprovalKey] =>
[ReturnURL] => http://success-url-area.com
[ReverseAllParallelPaymentsOnError] => false
[SenderEmail] => sender#email.com
[Status] => INCOMPLETE
[TrackingID] =>
[Receiver] => Array
(
[Amount] => 5.00
[Email] => receiver#email.com
[InvoiceID] =>
[PaymentType] => SERVICE
[Primary] => true
)
[XMLRequest] => <?xml version="1.0" encoding="utf-8"?><PaymentDetailsRequest xmlns="http://svcs.paypal.com/types/ap"><requestEnvelope xmlns=""><detailLevel>ReturnAll</detailLevel><errorLanguage>en_US</errorLanguage></requestEnvelope><payKey xmlns="">my-paykey</payKey></PaymentDetailsRequest>
[XMLResponse] => <?xml version='1.0' encoding='UTF-8'?><ns2:PaymentDetailsResponse xmlns:ns2="http://svcs.paypal.com/types/ap"><responseEnvelope><timestamp>2013-03-20T09:45:02.585-07:00</timestamp><ack>Success</ack><correlationId>4d31bf900a109</correlationId><build>5472483</build></responseEnvelope><cancelUrl>http://my-cancel-url.com</cancelUrl><currencyCode>TRY</currencyCode><paymentInfoList><paymentInfo><transactionId>my-transaction-id</transactionId><transactionStatus>COMPLETED</transactionStatus><receiver><amount>5.00</amount><email>receiver#email.com</email><primary>true</primary><paymentType>SERVICE</paymentType><accountId>7VYWTSCQKWPAL</accountId></receiver><refundedAmount>0.00</refundedAmount><pendingRefund>false</pendingRefund><senderTransactionId>7P642947V2872150G</senderTransactionId><senderTransactionStatus>COMPLETED</senderTransactionStatus></paymentInfo><paymentInfo><receiver><amount>4.60</amount><email>soulsmasher#gmail.com</email><primary>false</primary><paymentType>SERVICE</paymentType><accountId>7UZSWUVKCU4UW</accountId></receiver><refundedAmount>0.00</refundedAmount><pendingRefund>false</pendingRefund></paymentInfo></paymentInfoList><returnUrl>http://success-url-area.com</returnUrl><senderEmail>sender#email.com</senderEmail><status>INCOMPLETE</status><payKey>my-paykey</payKey><actionType>PAY_PRIMARY</actionType><feesPayer>PRIMARYRECEIVER</feesPayer><reverseAllParallelPaymentsOnError>false</reverseAllParallelPaymentsOnError><sender><email>sender#email.com</email><accountId>Y2BSLXZ8DQYY2</accountId><useCredentials>false</useCredentials></sender></ns2:PaymentDetailsResponse>
)
When I try to execute refund, providing paykey, transaction ID (which I got from the request above), and sender email (which will get refund) this error comes up (you can see the raw request and responses below):
Array
(
[Errors] => Array
(
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 589061
[ExceptionID] =>
[Message] => The receiver sender#email.com is invalid for this refund
[Parameter] => sender#email.com
[Severity] => Error
[Subdomain] => Application
)
)
[Ack] => Failure
[Build] => 5472483
[CorrelationID] => 2a1630b772ee0
[Timestamp] => 2013-03-20T09:52:10.986-07:00
[EncryptedTransactionID] =>
[RefundFeeAmount] =>
[RefundGrossAmount] =>
[RefundHasBecomeFull] =>
[RefundNetAmount] =>
[RefundStatus] =>
[RefundTransactionStatus] =>
[TotalOfAllRefunds] =>
[Receiver] => Array
(
[Amount] =>
[Email] =>
[InvoiceID] =>
[PaymentType] =>
[Primary] =>
)
[RawRequest] => <?xml version="1.0" encoding="utf-8"?><RefundRequest xmlns="http://svcs.paypal.com/types/ap"><requestEnvelope xmlns=""><detailLevel>ReturnAll</detailLevel><errorLanguage>en_US</errorLanguage></requestEnvelope><currencyCode>TRY</currencyCode><payKey xmlns="">my-paykey</payKey><receiverList xmlns=""><receiver xmlns=""><amount xmlns="">1.00</amount><email xmlns="">sender#email.com</email><paymentType xmlns="">SERVICE</paymentType></receiver></receiverList><transactionId xmlns="">1VL98806A27476639</transactionId></RefundRequest>
[RawResponse] => <?xml version='1.0' encoding='UTF-8'?><ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/ap"><responseEnvelope><timestamp>2013-03-20T09:52:10.986-07:00</timestamp><ack>Failure</ack><correlationId>2a1630b772ee0</correlationId><build>5472483</build></responseEnvelope><error><errorId>589061</errorId><domain>PLATFORM</domain><subdomain>Application</subdomain><severity>Error</severity><category>Application</category><message>The receiver sender#email.com is invalid for this refund</message><parameter>sender#email.com</parameter></error></ns3:FaultMessage>
)
1
Also when I don't provide transaction ID and leave the rest to PayPal, the issue changes to this (raw XML request are below the array):
Array
(
[Errors] => Array
(
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 589036
[ExceptionID] =>
[Message] => The currency code is missing or doesn't match the code in the payment request
[Parameter] =>
[Severity] => Error
[Subdomain] => Application
)
)
[Ack] => Failure
[Build] => 5472483
[CorrelationID] => e3fc5e41040f3
[Timestamp] => 2013-03-20T10:02:29.233-07:00
[EncryptedTransactionID] =>
[RefundFeeAmount] =>
[RefundGrossAmount] =>
[RefundHasBecomeFull] =>
[RefundNetAmount] =>
[RefundStatus] =>
[RefundTransactionStatus] =>
[TotalOfAllRefunds] =>
[Receiver] => Array
(
[Amount] =>
[Email] =>
[InvoiceID] =>
[PaymentType] =>
[Primary] =>
)
[RawRequest] => <?xml version="1.0" encoding="utf-8"?><RefundRequest xmlns="http://svcs.paypal.com/types/ap"><requestEnvelope xmlns=""><detailLevel>ReturnAll</detailLevel><errorLanguage>en_US</errorLanguage></requestEnvelope><currencyCode>TRY</currencyCode><payKey xmlns="">AP-52A99028X8685964M</payKey><receiverList xmlns=""><receiver xmlns=""><amount xmlns="">1.00</amount><email xmlns="">sender#email.com</email><paymentType xmlns="">SERVICE</paymentType></receiver></receiverList></RefundRequest>
[RawResponse] => <?xml version='1.0' encoding='UTF-8'?><ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/ap"><responseEnvelope><timestamp>2013-03-20T10:02:29.233-07:00</timestamp><ack>Failure</ack><correlationId>e3fc5e41040f3</correlationId><build>5472483</build></responseEnvelope><error><errorId>589036</errorId><domain>PLATFORM</domain><subdomain>Application</subdomain><severity>Error</severity><category>Application</category><message>The currency code is missing or doesn't match the code in the payment request</message></error></ns3:FaultMessage>
)
1
As you can see, I've already provided the CurrencyCode, also the sender's email adress is taken from the request itself to prevent typos. Even if I hardcode it doesn't change the situation.
Can you help me, what am I missing?
Thanks,
check the documentation say by paypal here
Turkish Lira TRY
NOTE:This currency is supported as a payment currency and a currency balance for in-country PayPal accounts only.
Related
I am looking for the php code syntax to capture if the call was successful or failed to stripe API. I need to capture one of the objects property to determine this but I am not sure what the best approach is.
Here's a sample response from a successful ACH api charge. I am looking for the php code syntax to capture if call was successful or failed
Stripe\Charge Object
(
[id] => py_1EFlRJBuwnzOEo57Poikh194
[object] => charge
[amount] => 50
[amount_refunded] => 0
[application] =>
[application_fee] =>
[application_fee_amount] =>
[balance_transaction] => txn_1EFlRJBuwnzOEo57dupt8SWp
[captured] => 1
[created] => 1553015365
[currency] => usd
[customer] => cus_Ec6cAdg6N2yYcF
[description] =>
[destination] =>
[dispute] =>
[failure_code] =>
[failure_message] =>
[fraud_details] => Array
(
)
[invoice] =>
[livemode] =>
[metadata] => Stripe\StripeObject Object
(
)
[on_behalf_of] =>
[order] =>
[outcome] => Stripe\StripeObject Object
(
[network_status] => approved_by_network
[reason] =>
[risk_level] => not_assessed
[seller_message] => Payment complete.
[type] => authorized
)
[paid] =>
[payment_intent] =>
[receipt_email] =>
[receipt_number] =>
[receipt_url] => https://pay.stripe.com/receipts/acct_1E8sOiBuwnzOEo57/py_1EFlRJBuwnzOEo57Poikh194/rcpt_EjDtGP7iknHI9RCBJ3iUODNC6bVBVyM
[refunded] =>
[refunds] => Stripe\Collection Object
(
[object] => list
[data] => Array
(
)
[has_more] =>
[total_count] => 0
[url] => /v1/charges/py_1EFlRJBuwnzOEo57Poikh194/refunds
)
[review] =>
[shipping] =>
[source] => Stripe\BankAccount Object
(
[id] => ba_1E8sTZBuwnzOEo57MKqXEvb7
[object] => bank_account
[account_holder_name] => Rassi Stern
[account_holder_type] => individual
[bank_name] => STRIPE TEST BANK
[country] => US
[currency] => usd
[customer] => cus_Ec6cAdg6N2yYcF
[fingerprint] => 9l7up0pswCYSO7eu
[last4] => 6789
[metadata] => Stripe\StripeObject Object
(
)
[routing_number] => 110000000
[status] => verified
)
[source_transfer] =>
[statement_descriptor] =>
[status] => pending
[transfer_data] =>
[transfer_group] =>
)
Are you using the Stripe PHP library?
I implemented something like this:
try {
$charge = \Stripe\Charge::create(array(
"amount" => $amount, // in pence - min 30p
"currency" => $currency,
"description" => $description,
"statement_descriptor" => $statementDescriptor,
"source" => $token,
"metadata" => array (
'code' => $code
),
"receipt_email" => $email
));
$success = true;
} catch(\Stripe\Error\Card $e) {
$success = false;
// Some other stuff to capture the reason for failure and tell the user etc.
}
If you're not using their library, it's probably worth investigating it: there are a lot of varying reasons why a payment could succeed or fail, so looking through that massive Charge Object for the answer may not 100% yield the results you want.
You can fetch the value of the "paid" OR "status" parameters from the charge object.
$success = json_encode($charge->paid); // Expected value = true
$success = json_encode($charge->status); // Expected value = succeeded
Then you can do your check:
if($success) { // or $success == "succeeded" depending on which array key you go for.
// Payment succeeded! Do something...
} else {
print_r(json_encode($charge->failure_message));
// Do something else...
}
The code may also work without json_encode(), I've found that my code is less buggy by using json_encode.
This is as per the Stripe API Docs: https://stripe.com/docs/api/charges/create
I am trying to build an online form that a user can enter their invoice number, the webserver will then interface with the Xero API to GET the invoice details and populate some additional fields for payment.
I have already got the form logic built and in place however I have no clue of how to start with the Xero API.
I've created a private app and have the required keys but I cannot find any documentation on how to actually go about setting up the API call in PHP.
Any help would be much appreciated.
**** UPDATE ****
I was able to get the API working using the following:
function GetInvData ($InvNumber) {
try {
$config = [
'oauth' => [
'consumer_key' => 'REDACTED',
'rsa_private_key' => 'REDACTED',
],
];
$xero = new PrivateApplication($config);
//$invoice = $xero->load(\XeroPHP\Models\Accounting\Invoice::class)->where('InvoiceNumber',$InvNumber)->execute();
$invoice = $xero->load('Accounting\Invoice')
->where('InvoiceNumber',$InvNumber)
->execute();
}
catch(\Exception $ex) {
var_dump($ex);
}
return ($invoice);
}
However what is returned is the most complex piece of JSON I have ever laid eyes on.... Probably not saying much.
All I need to be able to extract is the the Invoice Amount, The Customer name and Their email address, can anybody assist with this?
XeroPHP\Remote\Collection Object
(
[_associated_objects:protected] =>
[storage:ArrayObject:private] => Array
(
[0] => XeroPHP\Models\Accounting\Invoice Object
(
[_data:protected] => Array
(
[Type] => ACCREC
[Contact] => XeroPHP\Models\Accounting\Contact Object
(
[_data:protected] => Array
(
[ContactID] => cf6eef48-cda3-4862-8518-4d631ea54c1c
[ContactNumber] =>
[AccountNumber] =>
[ContactStatus] =>
[Name] => REDACTED
[FirstName] =>
[LastName] =>
[EmailAddress] =>
[SkypeUserName] =>
[ContactPersons] =>
[BankAccountDetails] =>
[TaxNumber] =>
[AccountsReceivableTaxType] =>
[AccountsPayableTaxType] =>
[Addresses] =>
[Phones] =>
[IsSupplier] =>
[IsCustomer] =>
[DefaultCurrency] =>
[XeroNetworkKey] =>
[SalesDefaultAccountCode] =>
[PurchasesDefaultAccountCode] =>
[SalesTrackingCategories] =>
[PurchasesTrackingCategories] =>
[TrackingCategoryName] =>
[TrackingCategoryOption] =>
[PaymentTerms] =>
[UpdatedDateUTC] =>
[ContactGroups] =>
[Website] =>
[BrandingTheme] =>
[BatchPayments] =>
[Discount] =>
[Balances] =>
[HasAttachments] =>
)
[_dirty:protected] => Array
(
)
[_associated_objects:protected] => Array
(
[Contact] => XeroPHP\Models\Accounting\Invoice Object
*RECURSION*
)
[_application:protected] =>
)
[LineItems] =>
[Date] => DateTime Object
(
[date] => 2019-03-05 00:00:00.000000
[timezone_type] => 3
[timezone] => Australia/Melbourne
)
[DueDate] => DateTime Object
(
[date] => 2019-03-12 00:00:00.000000
[timezone_type] => 3
[timezone] => Australia/Melbourne
)
[LineAmountTypes] => Exclusive
[InvoiceNumber] => Inv-1521
[Reference] => Feb 2019
[BrandingThemeID] => c560d364-0331-4677-a529-8ce702559165
[Url] =>
[CurrencyCode] => AUD
[CurrencyRate] => 1
[Status] => AUTHORISED
[SentToContact] => 1
[ExpectedPaymentDate] =>
[PlannedPaymentDate] =>
[SubTotal] => 2150
[TotalTax] => 215
[Total] => 2365
[TotalDiscount] =>
[InvoiceID] => f5cfaed4-db9b-41f3-94e5-a025c2bc898a
[HasAttachments] =>
[Payments] =>
[Prepayments] =>
[Overpayments] =>
[AmountDue] => 2365
[AmountPaid] => 0
[FullyPaidOnDate] =>
[AmountCredited] => 0
[UpdatedDateUTC] => DateTime Object
(
[date] => 2019-03-05 00:32:01.813000
[timezone_type] => 3
[timezone] => UTC
)
[CreditNotes] =>
)
[_dirty:protected] => Array
(
)
[_associated_objects:protected] => Array
(
)
[_application:protected] => XeroPHP\Application\PrivateApplication Object
(
[config:protected] => Array
(
[xero] => Array
(
[site] => https://api.xero.com
[base_url] => https://api.xero.com
[core_version] => 2.0
[payroll_version] => 1.0
[file_version] => 1.0
[model_namespace] => \XeroPHP\Models
)
[oauth] => Array
(
[signature_method] => RSA-SHA1
[signature_location] => header
[authorize_url] => https://api.xero.com/oauth/Authorize
[request_token_path] => oauth/RequestToken
[access_token_path] => oauth/AccessToken
[consumer_key] => REDACTED
[rsa_private_key] => REDACTED
[token] => REDACTED
)
[curl] => Array
(
[10018] => XeroPHP
[78] => 30
[13] => 20
[64] => 2
[81] => 2
[52] =>
[10004] =>
[10006] =>
[10102] =>
)
)
[oauth_client:protected] => XeroPHP\Remote\OAuth\Client Object
(
[config:XeroPHP\Remote\OAuth\Client:private] => Array
(
[signature_method] => RSA-SHA1
[signature_location] => header
[authorize_url] => https://api.xero.com/oauth/Authorize
[request_token_path] => oauth/RequestToken
[access_token_path] => oauth/AccessToken
[consumer_key] => REDACTED
[rsa_private_key] => REDACTED
[token] => REDACTED
)
[token_secret:XeroPHP\Remote\OAuth\Client:private] =>
[verifier:XeroPHP\Remote\OAuth\Client:private] =>
)
)
)
)
)
You're pretty much asking how to do the whole thing which people don't take kindly to here. Good job getting the API call done, it might take a while before you completely understand what goes on with each line but it's not required.
Now that you've got that part done you just need to work with the data that Xero gives you back, well rather what xero-php (which is the library you're using) gives you back. What you've posted is not JSON, it's just a dump (text representation) of the data as it exists as an object in your code.
That object is a Collection of Invoices, but it's just a singular invoice in your case. It will always return a Collection even if you have really specific search queries, but you can always make yourself a little check to make sure the Collection only has one invoice if you're only expecting one.
So, for what you actually want (Invoice Amount, The Customer name and Their email address), here's the next lines of code.
Invoice Amount:
$invoice->Invoices[0]->Total;
Customer Name:
$invoice->Invoices[0]->Contact->Name;
Email Address:
$invoice->Invoices[0]->Contact->EmailAddress;
Invoices[0] is used to grab the first Invoice in the Collection, so it assumes there's only one. Hopefully that points you in the right direction.
Ended up Getting it working with the following:
function GetInvData ($InvNumber) {
global $xero;
$return = array('AmountDue' => null, 'Customer' => null, 'EmailAddress' => null);
try {
//throw new Exception("Test");
$invoices = $xero->load(Accounting\Invoice::class)
->where('InvoiceNumber',$InvNumber)
->where('Status', 'AUTHORISED')
->execute();
$invoice = $invoices->first();
if(empty($invoice)){
$return = '';
}
else {
$invoiceCount = count($invoice);
if($invoiceCount > 1) {
throw new \Exception("Managed to find [" . $invoiceCount . "] with Invoice ID [" . $InvNumber . "]. Expected this to be unique.");
}
$contact = $invoice->getContact();
$return['AmountDue'] = $invoice->getAmountDue();
$return['Customer'] = $contact->getName();
$return['EmailAddress'] = $contact->getEmailAddress();
}
}
catch(\Exception $ex) {
$return = LogException($ex);
}
return $return;
}
Thanks everyone for the assistance.
I am very new in square payment.
I get response below. Now I need transaction ID from this response.
What's the best way to get it from this response?
---->Array
(
[*errors] =>
[*transaction] => SquareConnect\Model\Transaction Object
(
[id:protected] => 14bad261-60a6-56d7-6422-3ec8b7cdd10e
[location_id:protected] => CBASEGb8XMvdzZkrjf0H3PiMRi8gAQ
[created_at:protected] => 2018-03-12T10:23:33Z
[tenders:protected] => Array
(
[0] => SquareConnect\Model\Tender Object
(
[id:protected] => 7924ab32-9544-5139-673e-8ff5d0767858
[location_id:protected] => CBASEGb8XMvdzZkrjf0H3PiMRi8gAQ
[transaction_id:protected] => 14bad261-60a6-56d7-6422-3ec8b7cdd10e
[created_at:protected] => 2018-03-12T10:23:33Z
[note:protected] => Online Transaction
[amount_money:protected] => SquareConnect\Model\Money Object
(
[amount:protected] => 100
[currency:protected] => USD
)
[tip_money:protected] =>
[processing_fee_money:protected] =>
[customer_id:protected] =>
[type:protected] => CARD
[card_details:protected] => SquareConnect\Model\TenderCardDetails Object
(
[status:protected] => CAPTURED
[card:protected] => SquareConnect\Model\Card Object
(
[id:protected] =>
[card_brand:protected] => VISA
[last_4:protected] => 1111
[exp_month:protected] =>
[exp_year:protected] =>
[cardholder_name:protected] =>
[billing_address:protected] =>
[fingerprint:protected] => 9334946c94d2a20de8b1e267cc221a23298daed43b44621b4f44a0d032f0fc88
)
[entry_method:protected] => KEYED
)
[cash_details:protected] =>
[additional_recipients:protected] =>
)
)
$result->getTransaction()->getId();
i am recieveing this response after a transaction but i am not able to find the success or failure response,also i am not aware of the flow please correct me if i am wrong,
we have a sandbox account on square up we have an ecommerce web.
store with buy now option after submitting the form with nounce and
correction location id we are moved to process payments file where.
it displays the response after a transaction is made.
Response
SquareConnect\Model\ChargeResponse Object
(
[errors:protected] =>
[transaction:protected] => SquareConnect\Model\Transaction Object
(
[id:protected] => 1d034209-12cf-5d13-72f4-62247bb49132
[location_id:protected] => CBASEB5G76QcIpEWB0w38Mi2vWUgAQ
[created_at:protected] => 2017-07-27T05:45:34Z
[tenders:protected] => Array
(
[0] => SquareConnect\Model\Tender Object
(
[id:protected] => 675e208b-caf3-5f11-7482-1eacff13da64
[location_id:protected] => CBASEB5G76QcIpEWB0w38Mi2vWUgAQ
[transaction_id:protected] => 1d034209-12cf-5d13-72f4-62247bb49132
[created_at:protected] => 2017-07-27T05:45:34Z
[note:protected] => Online Transaction
[amount_money:protected] => SquareConnect\Model\Money Object
(
[amount:protected] => 100
[currency:protected] => USD
)
[processing_fee_money:protected] =>
[customer_id:protected] =>
[type:protected] => CARD
[card_details:protected] => SquareConnect\Model\TenderCardDetails Object
(
[status:protected] => CAPTURED
[card:protected] => SquareConnect\Model\Card Object
(
[id:protected] =>
[card_brand:protected] => DISCOVER
[last_4:protected] => 9697
[exp_month:protected] =>
[exp_year:protected] =>
[cardholder_name:protected] =>
[billing_address:protected] =>
[fingerprint:protected] =>
)
[entry_method:protected] => KEYED
)
[cash_details:protected] =>
)
)
[refunds:protected] =>
[reference_id:protected] =>
[product:protected] => EXTERNAL_API
[client_id:protected] =>
[order:protected] =>
[shipping_address:protected] =>
)
)
If you get a transaction back, then your request was successful. If you get errors back, your request was not successful.
you ll get Transaction id return to the Redirect URL
I'm trying to get transaction details of a PayPal account, which I was successfully in doing so, but I get this long (what i assume is an array) and I need to insert the details into a MySQL database. I've tried several foreach methods but apparently I am doing something wrong.
This is the reponse from PayPal after successful request (stored as $httpParsedResponse)
TransactionSearch Completed Successfully: Array (
[L_TIMESTAMP0] => 2012%2d08%2d14T18%3a46%3a00Z
[L_TIMESTAMP1] => 2012%2d08%2d14T18%3a45%3a32Z
[L_TIMESTAMP2] => 2012%2d08%2d13T01%3a45%3a48Z
[L_TIMESTAMP3] => 2012%2d08%2d13T01%3a34%3a12Z
[L_TIMEZONE0] => GMT
[L_TIMEZONE1] => GMT
[L_TIMEZONE2] => GMT
[L_TIMEZONE3] => GMT
[L_TYPE0] => Payment
[L_TYPE1] => Payment
[L_TYPE2] => Payment
[L_TYPE3] => Transfer
[L_EMAIL0] => pmd_1333866_per%40yahoo%2ecom
[L_EMAIL1] => pmd_1333866_per%40yahoo%2ecom
[L_EMAIL2] => pmd_1333866_per%40yahoo%2ecom
[L_NAME0] => Joshua%20O
[L_NAME1] => Joshua%20O
[L_NAME2] => Joshua%20O
[L_NAME3] => PayPal
[L_TRANSACTIONID0] => 58289472YK615973G
[L_TRANSACTIONID1] => 4U113116FL1819900
[L_TRANSACTIONID2] => 2X978155KR373471P
[L_TRANSACTIONID3] => 3TH38971MF599302V
[L_STATUS0] => Completed
[L_STATUS1] => Completed
[L_STATUS2] => Completed
[L_STATUS3] => Completed
[L_AMT0] => %2d100%2e00
[L_AMT1] => %2d50%2e00
[L_AMT2] => %2d200%2e00
[L_AMT3] => 2000%2e00
[L_CURRENCYCODE0] => USD
[L_CURRENCYCODE1] => USD
[L_CURRENCYCODE2] => USD
[L_CURRENCYCODE3] => USD
[L_FEEAMT0] => 0%2e00
[L_FEEAMT1] => 0%2e00
[L_FEEAMT2] => 0%2e00
[L_FEEAMT3] => 0%2e00
[L_NETAMT0] => %2d100%2e00
[L_NETAMT1] => %2d50%2e00
[L_NETAMT2] => %2d200%2e00
[L_NETAMT3] => 2000%2e00
[TIMESTAMP] => 2012%2d08%2d25T17%3a59%3a01Z
[CORRELATIONID] => bf5b1a824d937
[ACK] => Success
[VERSION] => 51%2e0
[BUILD] => 3435050
)
Obviously enough I guess the array is structured as
[L_TIMESTAMP0]
[L_TIMESTAMP1]
[L_TIMESTAMP2]
and this continues for how ever many sets of transaction details there are for each set, ie timestamp, timezone, type, email, ect...
In this case there are 3 sets of transaction details but whatever solution needs to be able to loop through it wheither there is only 1 transaction pulled or 100.
Like I said the only goal here is to take this returned array from PayPal and insert into a MySQL database.
I hope this makes sense, any help at all would be greatly appreciated! Thanks!
Im sorry I had to edit my old question because im a newbie I guess - At any rate I think your code helped organize it a bit better, this is now the response I get... still confused on how to insert it into a mysql database tho...
Array ( [0] => Array ( [timestamp] => 2012%2d08%2d14T18%3a46%3a00Z
[timezone] => GMT
[type] => Payment
[email] => pmd_1333866_per%40yahoo%2ecom
[name] => Joshua%20O
[transactionid] => 58289472YK615973G
[status] => Completed
[amt] => %2d100%2e00
[feeamt] => 0%2e00
[netamt] => %2d100%2e00 )
[1] => Array ( [timestamp] => 2012%2d08%2d14T18%3a45%3a32Z
[timezone] => GMT
[type] => Payment
[email] => pmd_1333866_per%40yahoo%2ecom
[name] => Joshua%20O
[transactionid] => 4U113116FL1819900
[status] => Completed
[amt] => %2d50%2e00
[feeamt] => 0%2e00
[netamt] => %2d50%2e00 )
[2] => Array ( [timestamp] => 2012%2d08%2d13T01%3a45%3a48Z
[timezone] => GMT
[type] => Payment
[email] => pmd_1333866_per%40yahoo%2ecom
[name] => Joshua%20O
[transactionid] => 2X978155KR373471P
[status] => Completed
[amt] => %2d200%2e00
[feeamt] => 0%2e00
[netamt] => %2d200%2e00 )
[3] => Array ( [timestamp] => 2012%2d08%2d13T01%3a34%3a12Z
[timezone] => GMT
[type] => Transfer
[email] =>
[name] => PayPal
[transactionid] => 3TH38971MF599302V
[status] => Completed
[amt] => 2000%2e00
[feeamt] => 0%2e00
[netamt] => 2000%2e00 ) )
Two ideas are:
$numOfTransactions=intval((count($response)-5)/11);
where 5 is the number of values not duplicated for each transaction and 11 is the number of values for each transaction. This depends on the structure being reliable.
OR
$numOfTransactions=0;
foreach ($response as $key=>$value){
$check=strpos($key,'L_TIMESTAMP');
if ($check===false) break;
$numOfTransactions++;
}
Then you can loop through the response to structure your data
for ($i=0;$i<$numOfTransactions;$i++){
$data[$i]=array("timestamp"=>$response['L_TIMESTAMP'.$i],"timezone"=>$response['L_TIMEZONE'.$i]...);
}