Skip to content

Charges

waqastanoli10 edited this page Feb 12, 2020 · 1 revision

To charge a credit card or debit card (knet, mada, benefit) or an existing authorized transactions, you create a charge request. You can retrieve the individual charge as well as list all charges. Charges are identified by a unique random id. Charge id starts with "chg_".

Create a Charge

To charge a credit card or debit card (knet, mada) or an existing authorized transactions, you create a charge request. If your API key is in test mode, the card won't actually be charged, though everything else will occur as if in live mode. (Tap assumes that the charge would have completed successfully).

$charge_created = GoSell\Charges::create([
  "amount"=> 1,
  "currency"=> "KWD",
  "threeDSecure"=> true,
  "save_card"=> false,
  "description"=> "Test Description",
  "statement_descriptor"=> "Sample",
  "metadata"=> [
    "udf1"=> "test 1",
    "udf2"=> "test 2"
  ],
  "reference"=> [
    "transaction"=> "txn_0001",
    "order"=> "ord_0001"
  ],
  "receipt"=> [
    "email"=> false,
    "sms"=> true
  ],
  "customer"=> [
    "first_name"=> "test",
    "middle_name"=> "test",
    "last_name"=> "test",
    "email"=> "test@test.com",
    "phone"=> [
      "country_code"=> "965",
      "number"=> "50000000"
    ]
  ],
  "source"=> [
    "id"=> "src_all"
  ],
  "post"=> [
    "url"=> "http://your_website.com/post_url"
  ],
  "redirect"=> [
    "url"=> "http://your_website.com/redirect_url"
  ]
]);

echo '<pre>';var_dump($charge_created);

Retrieve a Charge

Retrieves the details of a charge that has previously been created. Supply the unique charge id that was returned from your previous request, and Tap will return the corresponding charge information. The same information is returned when creating the charge.

GoSell\Charges::retrieve($charge_created->id)

Update a Charge

Updates the specified charge by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

This request accepts only the description, metadata and receipt arguments.

GoSell\Charges::update($retrieved_charge->id,[
  "description"=> "test",
  "receipt"=> [
    "email"=> false,
    "sms"=> true
  ],
  "metadata"=> [
    "udf2"=> "testing update"
  ]
]);

List all Charges

Returns a list of charges you’ve previously created. The charges are returned in sorted order, with the most recent charges appearing first.

$charges_all = GoSell\Charges::all([
  "period"=> [
    "date"=> [
      "from"=> time() - (30 * 24 * 60 * 60),//last 30 days
      "to"=> time() + (30 * 24 * 60 * 60)//next 30 days
    ]
  ],
  "status"=> "",
  "starting_after"=> "",
  "limit"=> 25
]);

var_dump($charges_all);