ウェブサイトのメンバーに毎週請求したい. 住所、電話番号、都市、州などのクレジットカード情報をテーブルに保存しました。
PHP で PayPal REST API を使用しています。
これが私のコードです:
while ($row2 = $res2->fetch_assoc ())
{
// ### Address
// Base Address object used as shipping or billing
// address in a payment. [Optional]
$addr = new Address ();
if ($row2 ['billing_address'])
$addr->setLine1 ($row2 ['billing_address']);
if ($row2 ['billing_address2'])
$addr->setLine2 ($row2 ['billing_address2']);
if ($row2 ['billing_city'])
$addr->setCity ($row2 ['billing_city']);
if ($row2 ['billing_state'])
$addr->setState ($row2 ['billing_state']);
if ($row2 ['billing_zip'])
$addr->setPostal_code ($row2 ['billing_zip']);
$addr->setCountry_code ("US");
if ($row2 ['billing_phone'])
$addr->setPhone ($row2 ['billing_phone']);
// Decrypt Credit Cart #
$credit_card_number = decrypt ($row2 ['cc_number'], 'hassan');
$cc_name_array = explode (" ", $row2 ['cc_name']);
$cc_name_array_count = count ($cc_name_array);
$cc_f_name = $cc_name_array [0];
$cc_l_name = "";
for ($i = 1; $i < $cc_name_array_count; $i++)
{
$cc_l_name .= str_replace (array ("&", "."), "", $cc_name_array [$i]) . " ";
}
$cc_l_name = trim ($cc_l_name);
// ### CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
$card = new CreditCard ();
if (strtolower ($row2 ['cc_type']) == "visa")
{
$card->setType ('visa');
}
elseif (strtolower ($row2 ['cc_type']) == "mastercard")
{
$card->setType ('mastercard');
}
elseif (strtolower ($row2 ['cc_type']) == "discover cards")
{
$card->setType ('discover');
}
elseif (strtolower ($row2 ['cc_type']) == "american express")
{
$card->setType ('amex');
}
$card->setNumber ($credit_card_number);
$card->setExpire_month ($row2 ['cc_expiry_month']);
$card->setExpire_year ($row2 ['cc_expiry_year']);
$card->setCvv2 ($row2 ['cc_cvv']);
$card->setFirst_name ($cc_f_name);
$card->setLast_name ($cc_l_name);
$card->setBilling_address ($addr);
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// Use a Payer ID (A unique identifier of the payer generated
// and provided by the facilitator. This is required when
// creating or using a tokenized funding instrument)
// and the `CreditCardDetails`
$fi = new FundingInstrument ();
$fi->setCredit_card ($card);
// ### Payer
// A resource representing a Payer that funds a payment
// Use the List of `FundingInstrument` and the Payment Method
// as 'credit_card'
$payer = new Payer ();
$payer->setPayment_method ("credit_card");
$payer->setFunding_instruments (array ($fi));
// ### Amount
// Let's you specify a payment amount.
$amount = new Amount ();
$amount->setCurrency ("USD");
//$amount->setTotal ("1.00");
$amount->setTotal ($row ['billing_cost']);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = new Transaction ();
$transaction->setAmount ($amount);
$transaction->setDescription ("Commission deducted for the sold property.");
// ### Payment
// A Payment Resource; create one using
// the above types and intent as 'sale'
$payment = new Payment ();
$payment->setIntent ("sale");
$payment->setPayer ($payer);
$payment->setTransactions (array ($transaction));
// ### Create Payment
// Create a payment by posting to the APIService
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the status;
try
{
$payment->create ($apiContext);
}
catch (\PPConnectionException $ex)
{
echo "Exception: " . $ex->getMessage () . PHP_EOL;
var_dump ($ex->getData());
exit (1);
}
if ($payment->getId ())
{
$br_date = time ();
$insert = "INSERT INTO `billing_reports`
(`sh_id`, `listing_id`, `billed_person_type`, `billed_person_id`, `cc_type`, `cc_name`, `cc_number`, `cc_expiry_month`, `cc_expiry_year`, `cc_cvv`, `billing_amount`, `payment_id`, `br_date`, `status`)
VALUES ('" . $row ['sh_id'] . "', '" . $row ['listing_id'] . "', '" . $row2 ['member_type'] . "', '" . $row2 ['member_id'] . "', '" . $row2 ['cc_type'] . "', '" . $row2 ['cc_name'] . "', '" . $row2 ['cc_number'] . "', '" . $row2 ['cc_expiry_month'] . "', '" . $row2 ['cc_expiry_year'] . "', '" . $row2 ['cc_cvv'] . "', '" . $row ['billing_cost'] . "', '" . $payment->getId () . "', '" . $br_date . "', 1)";
$GLOBALS ['mysqli']->query ($insert) or die ($GLOBALS ['mysqli']->error . __LINE__);
//unset ($addr, $card, $fi, $payer, $amount, $transaction, $payment);
}
}
ループの反復ごとに、テーブルから新しいメンバーが取得され、その情報が REST API 変数に入力されます。
しかし問題は、2 人以上の連続したメンバーが同じクレジット カード情報を持っている場合、このループが正常に機能することです。情報が変更されると、トランザクションは通過しません。
私はPayPalの専門家ではありません。したがって、皆さんからの助けが必要です。問題は $payment オブジェクトにあると思います。新しい値でインスタンス化されません。どんな種類の助けも素晴らしいでしょう。私はすでにこれに3日を費やしました:(